我在R中使用ggplot2繪製大量數據集。爲了使繪圖更易於比較,我設置了y尺度的極限,但事實證明, ,沒有任何東西繪製在劇情的「天然頂部」之上。ggplot2 - 缺少一些x-labes和網格線
例如,對於這個情節: Plot with missing labels and lines http://sickel.net/misc/output.png 我試圖設置頂部y值500(看着上方的空白,我已成功地),但如何讓ggplot還繪製標籤400,450和500以及相應的網格線?
數據在數據框df中分別與df $ dataset和df $ error一起作爲數據和錯誤級別。我的繪圖代碼目前是
max = max(df$dataset + df$error) * 1.05
if(max > 300) max=505
dataplot = ggplot(data=df, aes(x=species,y=dataset,fill=dim,ylim=c(0,max)))
dataplot = dataplot+geom_bar(position=position_dodge())
dataplot = dataplot+scale_fill_manual(values=c("#BBBBBB", "#444444"))
dataplot = dataplot + ylab(ylab) + xlab(xlab) + opts(legend.title=theme_blank())
limits <- aes(ymax = df$dataset+df$error, ymin=df$dataset-df$error)
dodge = position_dodge(width=0.9)
dataplot = dataplot + geom_errorbar(limits, position=dodge, width=0.5)
dataplot = dataplot + opts(panel.background = theme_rect(fill='white', colour='white'))
dataplot = dataplot + opts(panel.grid.major = theme_line(colour = "gray"))
# dataplot = dataplot + coord_cartesian(ylim=c(0, max))
# dataplot = dataplot + scale_y_continuous(limits=c(0, max))
dataplot = dataplot +
opts(axis.text.x = theme_text(colour = "black",angle=90),
axis.text.y = theme_text(colour = "black"))
dataplot = dataplot + opts(legend.key.size = unit(0.3, "cm"))
print(dataplot)
從上註釋掉線可以看出,我已經試過coord_cartesian,scale_y_continous以及本Y型LIM沒有任何的運氣(是的,我知道coord_cartesian被放大)
'dataplot + ylim(0,max)'做你想要的嗎? – smillig
抱歉無關的回覆,但無法找到聯繫電子郵件。從一個Clef到另一個Clerk(看我的標誌):你選擇什麼工具? –
我可以肯定地告訴你,你在'aes'裏面使用'ylim'不會做你想做的事(並且永遠不會做任何有用的事情)。但是,如果你能提供一個可重複的例子,我認爲它會有所幫助。 – joran