我试图将以下示例中的值轴限制为0到1,但似乎不接受它。哪里错了?
library(ggplot2)
tmp<- data.frame(testname=c("b","b","a","a","c","c"), variable=c(40,50,40,50,40,50), value=c(0.5,0.6,0.7,0.8, 0.4, 0.8))
tmp
tmp$testname <- factor(tmp$testname, levels=unique(as.character(tmp$testname)))
ggplot(tmp, aes(testname, value)) + geom_point(aes(group=variable, colour= variable), ) + theme_bw() + coord_cartesian(xlim=c(0, 1)) +
coord_flip()
答案 0 :(得分:2)
删除coord_cartesian
参数并使用coord_flip
coord_flip(ylim=c(0,1))
参数中设置y轴的限制
使用您的代码,这对我有用:
library(ggplot2)
tmp<- data.frame(testname=c("b","b","a","a","c","c"), variable=c(40,50,40,50,40,50), value=c(0.5,0.6,0.7,0.8, 0.4, 0.8))
tmp
tmp$testname <- factor(tmp$testname, levels=unique(as.character(tmp$testname)))
ggplot(tmp, aes(testname, value)) +
geom_point(aes(group=variable, colour= variable)) +
theme_bw() + coord_flip(ylim=c(0,1))