Can anyone help me to set the limits of the horizontal axis in the figure to (0,1) please? 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.
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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.