2010-06-28 59 views
5

在呈現實際數據之前,我想繪製一張與數據一致的繪圖,但沒有數據點。這有助於我解釋如何解釋這樣一個情節,而不會讓觀衆分散情節中的實際數據。在空ggplot中獲取圖例着色

所以在下面的代碼中,我基本上想與geom_blank()交換geom_point()。沒問題。

但是,這也會從圖表代碼創建的圖例中移除顏色和大小信息。有沒有辦法讓它回來?

ggplot(vas, aes(x=time, y=pain, colour=light.color, size=light.intensity)) + 
    #geom_point(na.rm=FALSE) + 
    geom_blank() + 
    facet_wrap(~ppno) + 
    scale_colour_manual(values=cols) + 
    scale_y_continuous(name="VAS Pain (a.u.)") + 
    scale_x_continuous(name="Time (minutes)") 

什麼是適當的方式來獲取顏色指示回圖例(S)。現在它們只顯示特定參數(顏色或大小)的各個級別的值,而不顯示與特定級別一致的實際圖形元素(顏色或點的大小)。

回答

0

你可以繪製兩個geom_points() - 一個與你的背景顏色?

ggplot(cars, aes(x=speed, y=dist))+ 
geom_point(aes(col=speed))+ 
geom_point(colour="white")+ 
theme_bw() 
+0

謝謝你的建議! 我已經想到了這個想法,但放棄它,因爲我更喜歡ggplot()使用的默認灰度網格。 所以在這種情況下很難找到淡入背景的正確顏色(也因爲每個點必須有兩種顏色,一種是背景,另一種是與網格線相交,也是白色)。 – Paul 2010-06-28 14:20:45

+0

這是有道理的。你總是可以畫出這個傳奇,並且繪製一個空的陰謀。有點像這樣:http://learnr.wordpress.com/2009/05/26/ggplot2-two-or-more-plots-sharing-the-same-legend/ – Andreas 2010-06-28 15:49:12

2

如何隱藏繪圖窗口外的實際點?沿着這些路線的東西:

ggplot(cars, aes(x=speed+100, y=dist))+ #move x values to the right 
    geom_point(aes(col=speed))+ 
    scale_x_continuous(at=seq(5,125,by=5), limits=c(0,30)) #set plotting window 
0

最後,沿着以兄子的建議(即我最初不能得到工作,所以丟棄,unrightly左右),我想出了下面的代碼。

vas2 <- vas 
vas2$time <- vas2$time+181 
pp <- p %+% vas2 #p is the above plot assigned to a variable. 
pp + scale_x_continuous(name="Time (minutes)", limits=c(0,180)) 

所以大約就在您的數據移位,上軸,然後排除

1

一個簡單的方法那部分要做到這一點是使用了尺寸選項:

ggplot(vas, aes(x=time, y=pain, colour=light.color, size=light.intensity)) 
+ geom_point(size=0)