指定ylim时不显示geom_bar栏 [英] geom_bar bars not displaying when specifying ylim
问题描述
我在使用geom_bars时遇到问题,其中当我在y轴上指定限制时,条形图未呈现。我相信以下应该重现这个问题:
$ b $ $ p $ data< - structure(list(RoleCond = structure(c(1L,1L ,2L,2L),.Label = c(Buyer,Seller),class =factor),
ArgCond = structure(c(1L,2L,1L,2L),.Label = c (2210.71428571429,2142.70833333333,2282.40740740741,2346.2962962963),
se = c(20.1231042081511,16.7408757749718,20.1471554637891,15.708092540868),(无参数,参数),class =factor )),
.Names = c(RoleCond,ArgCond,mean,se),row.names = c(NA,-4L),class =data.frame)
library(ggplot2)
ggplot(data = data,aes(fill = RoleCond,y = mean,x = ArgCond))+
geom_bar(position =dodge,stat =限制,位置=闪避,宽度= 0.1,大小= .75)+
scale_y_continuous(限制= c(2000,2500))
这给了我这个
没有限制指定工作正常。 geom_errorbar()似乎与问题没有关系,但它确实说明了条形应该显示的位置。
我试过使用 coord_cartesian(ylim = c(2000,2500))
用于限制yaxis并获取条形图显示,但轴标签变得混乱起来,我不明白我在说什么,与它做。
感谢您的任何建议! (我使用R 2.15.0和ggplot2 0.9.0)
你可以用 library(scale)
:
+ scale_y_continuous(limits = c(2000,2500),oob = rescale_none)
改为这里。
I'm having a problem with geom_bars wherein the bars are not rendered when I specify limits on the y-axis. I believe the following should reproduce the problem:
data <- structure(list(RoleCond = structure(c(1L, 1L, 2L, 2L), .Label = c("Buyer", "Seller"), class = "factor"),
ArgCond = structure(c(1L, 2L, 1L, 2L), .Label = c("No Argument", "Argument"), class = "factor"),
mean = c(2210.71428571429, 2142.70833333333, 2282.40740740741, 2346.2962962963),
se = c(20.1231042081511, 16.7408757749718, 20.1471554637891, 15.708092540868)),
.Names = c("RoleCond", "ArgCond", "mean", "se"), row.names = c(NA, -4L), class = "data.frame")
library(ggplot2)
ggplot(data=data, aes(fill=RoleCond, y=mean, x=ArgCond)) +
geom_bar(position="dodge", stat="identity") +
geom_errorbar(limits, position=dodge, width=0.1, size=.75) +
scale_y_continuous(limits=c(2000,2500))
which gives me this
The same code without the limits specified works fine. The geom_errorbar() doesn't seem to be related to the problem, but it does illustrate where the bars should be showing up.
I've tried using coord_cartesian(ylim=c(2000,2500))
which works for limiting the yaxis and getting the bars to display, but the axis labels get messed up and I don't understand what I'm doing with it.
Thanks for any suggestions! (I'm using R 2.15.0 and ggplot2 0.9.0)
You could try, with library(scales)
:
+ scale_y_continuous(limits=c(2000,2500),oob = rescale_none)
instead, as outlined here.
这篇关于指定ylim时不显示geom_bar栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!