2017-07-16 68 views
0

我在ggplot2中创建了一个图表,我想将查看窗口的x轴放大到min = 40和max = 60。我现在的“scale_y_continuous”将标签更改为40-60,但实际图形保持不变。这里是我的代码,任何帮助将不胜感激!如何在ggplot2中设置查看窗口

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

+0

请加上输入采样数据,你所用的代码了。 – Prradep

回答

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

+0

你知道如何通过coord_lim继​​续coord_flip吗?它的工作原理,但我也试图实现一个坐标翻转,所以条形图变成水平,当我这样做时,它不会带来两个结束。 – SoccerAnalytics26

+1

工作。我最终使用'a + coord_flip(ylim = c(40,60))'。谢谢。 – SoccerAnalytics26

+0

我试图模仿样本数据集相同。 – Prradep