如何在ggplot2

时间:2017-07-16 16:15:59

标签: r plot ggplot2

我在ggplot2中制作了一个图表,我想将观察窗口的x轴放大到min = 40和max = 60。我现在对“scale_y_continuous”所做的更改标签的范围是40-60,但实际图形保持不变。这是我的代码,任何帮助将不胜感激!

library("ggplot2")
a<- ggplot(data=means_sort, aes(reorder(means_sort$nicknames, 
means_sort$pcts), y=means_sort$pcts))+
  geom_bar(stat="identity") +
  xlab("X") +
  ylab("Y")+
  scale_y_continuous(breaks = round(seq(min(40), max(60), by = 5),1))

Bar Graph

1 个答案:

答案 0 :(得分:0)

scale_x_continuous(limits = c(40, 60))coord_fixed(xlim = c(40, 60))可能对您有用。

p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
p

enter image description here

p + coord_fixed(xlim=c(15,20))

enter image description here

p + scale_x_continuous(limits = c(15,20)) 

enter image description here

根据OP的要求:

p + coord_flip(ylim=c(2,5))

enter image description here