![](/img/trans.png)
[英]How to sort x-axis names by sorting y-axis in R without ggplot2?
[英]R ggplot2: how to make x-axis lines not overlapping y-axis?
我经常从ggplot生成图表,并且我喜欢采用浅色设计(白色背景等)。除了x轴线与y轴线重叠之外,其他所有方法都可以正常工作,请参见屏幕截图中的红色标记:
我想要的显示在下面,此刻,我必须在Illustrator中编辑每个绘图...我希望x轴不与y轴线重叠(不在右侧和左侧) )。 我认为,这看起来更清洁。
有谁知道我怎么能做到这一点? 到目前为止,我还没有找到任何东西。因此,非常感谢您的帮助。
编辑(示例):
数据:
label_de proz
1: Dialekt / Sprache 37.6
2: Landschaft 52.1
3: Traditionen und Bräuche (Fasnacht, etc.) 20.4
4: Siedlungsraum (Gebäude usw.) 21.6
5: Sportclubs (Fussball, Eishockey, etc.) 13.4
6: Freunde und Bekannte 61.7
7: Familie 57.0
8: Bewohnerinnen / Bewohner 14.9
9: Kulinarisches Angebot (Essen, Trinken) 12.2
10: Freizeitangebot 18.6
11: Politisches Profil 5.8
12: Anderes 13.1
和ggplot代码(无顺序):
p <- ggplot(data=ggdata, aes(x=label_de, y=proz) ) +
geom_bar(stat="identity", position="dodge") +
ylim(0,100) +
coord_flip() +
theme_bw() + theme( strip.background = element_blank(),
panel.grid.major = element_line(colour = "grey80"),
panel.border = element_blank(),
axis.ticks = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.y = element_line(colour = "grey80"),
axis.text.y = element_text(hjust = 1),
legend.position="bottom")
您可以将scale expand= c(0,0)
添加到比例尺,然后移动标签以免被切碎。 随机数据示例
set.seed(123)
ggplot(data=data.frame(label_de=letters[1:10], proz = runif(10,0, 85)),
aes(x=label_de, y=proz)) +
geom_bar(stat="identity", position="dodge") +
coord_flip() +
# notice this part
scale_y_continuous(limits = c(0,100), expand = c(0,0)) +
theme_bw() +
theme( strip.background = element_blank(),
panel.grid.major = element_line(colour = "grey80"),
panel.border = element_blank(),
axis.ticks = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.y = element_line(colour = "grey80"),
axis.text.y = element_text(hjust = 1),
# notice this part
axis.text.x = element_text(hjust = 1),
legend.position="bottom")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.