[英]Adjust axis limit in bar plot ggplot2
Can anyone help me to set the limits of the horizontal axis in the figure to (0,1) please? 有人可以帮我将图中水平轴的限制设置为(0,1)吗? The code below does not work. 下面的代码不起作用。
set.seed(234)
data <- data.frame(var1 = c(rep('A',3),rep('B',3)),
var2 = runif(6),
var3 = rep(c('x1','x2','x3'),2))
ggplot(data,aes(x=var1,y=var2,fill=factor(var3))) +
geom_bar(stat="identity",position="dodge") +
scale_y_continuous(breaks=c(0,0.5,1.0)) +
coord_cartesian(ylim=c(0,1.0)) +
coord_flip()
No need for coord_cartesian(), you can pass the ylim arg into coord_flip() directly. 不需要coord_cartesian(),您可以将ylim arg直接传递到coord_flip()中。
set.seed(234)
library(ggplot2)
data <- data.frame(var1 = c(rep('A',3),rep('B',3)),
var2 = runif(6),
var3 = rep(c('x1','x2','x3'),2))
ggplot(data,aes(x=var1,y=var2,fill=factor(var3))) +
geom_bar(stat="identity",position="dodge") +
scale_y_continuous(breaks=c(0,0.5,1.0)) +
coord_flip(ylim = c(0, 1))
http://docs.ggplot2.org/0.9.3.1/coord_flip.html http://docs.ggplot2.org/0.9.3.1/coord_flip.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.