2

我试图将以下示例中的值轴限制为从 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()
4

1 回答 1

2

摆脱参数并在参数coord_cartesian中设置y轴的限制coord_flipcoord_flip(ylim=c(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_flip(ylim=c(0,1)) 
于 2013-07-10T17:11:14.493 回答