在X轴GGPLOT上的每个第二个标签之间添加空间或断开空间
如何在GGPLOT中X轴上的每个第二个标签之间添加一个空间或破裂,以在每组平台(FB,IG和TW)之间引入一定距离?
如果我尝试在数据框架中添加空白行,则ggplot将它们删除(即使在添加drop = false false scale_x_discrete之后)。
我也不想通过节省更大的图形来解决此问题(因为变量比我在此处包含的变量更多)。
这是代码:
Platform <- c("FB Left-wing", "FB Right-wing",
"IG Left-wing", "IG Right-wing",
"TW Left-wing", "TW Right-wing")
Ideology <- c("Left", "Right", "Left", "Right","Left", "Right")
CI_low <- c(1.049, 0.906, 1.212, 0.989, 1.122, 1.080)
CI_high <- c(1.299, 1.144, 1.483, 1.235, 1.362, 1.335)
CI_mid <- c(1.167, 1.018, 1.340, 1.105, 1.236, 1.201)
dat_figure <- data.frame(Platform, Ideology, CI_low, CI_high, CI_mid)
figure <- ggplot(dat_figure, aes(x = Platform, y = CI_mid, colour = Ideology)) +
scale_colour_manual(values = c("blue", "red")) +
geom_pointrange(aes(ymin = CI_low, ymax = CI_high)) +
ylim(0, 4) +
ylab("Odds Ratio") +
xlab("Platform and Ideology") +
theme_bw()
figure
和输出:
我想在'fb右翼和左右之间添加一个空间 - 翼'和“ IG右翼和TW左翼”。
谢谢。
How can I add a space or break between every second label on the x-axis in ggplot, to introduce some distance between each set of platforms (FB, IG, and TW)?
If I try adding blank rows to the dataframe, ggplot drops them (even after adding drop=FALSE to scale_x_discrete).
I also do not want to fix this by saving the figure larger (because there are more variables than what I include here).
Here is the code:
Platform <- c("FB Left-wing", "FB Right-wing",
"IG Left-wing", "IG Right-wing",
"TW Left-wing", "TW Right-wing")
Ideology <- c("Left", "Right", "Left", "Right","Left", "Right")
CI_low <- c(1.049, 0.906, 1.212, 0.989, 1.122, 1.080)
CI_high <- c(1.299, 1.144, 1.483, 1.235, 1.362, 1.335)
CI_mid <- c(1.167, 1.018, 1.340, 1.105, 1.236, 1.201)
dat_figure <- data.frame(Platform, Ideology, CI_low, CI_high, CI_mid)
figure <- ggplot(dat_figure, aes(x = Platform, y = CI_mid, colour = Ideology)) +
scale_colour_manual(values = c("blue", "red")) +
geom_pointrange(aes(ymin = CI_low, ymax = CI_high)) +
ylim(0, 4) +
ylab("Odds Ratio") +
xlab("Platform and Ideology") +
theme_bw()
figure
And the output:
I would like to add a space between 'FB Right-wing and IG Left-wing', and 'IG Right-wing and TW Left-wing'.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该解决方案并不是您所要求的,但是我认为这是可视化数据结构的一种方法:
This solution isn't exactly what you asked for, but I think it is one way to visualize the structure of data:
显示分类数据的一种常见方法是对其进行设定。这里为facet创建了
媒体
列。在2022-05-18上由 reprex软件包(v2.0.1)
One common way to display categorical data is to facet it. Here the
media
column is created for the facet.Created on 2022-05-18 by the reprex package (v2.0.1)