簡體   English   中英

在空的ggplot中獲取圖例着色

[英]Getting legend coloring in an empty ggplot

在呈現實際數據之前,我想制作一個與數據相同的圖,但之后沒有數據點。 這有助於我解釋如何解釋這樣的情節,而不會分散觀眾將在情節中的實際數據。

因此,在下面的代碼我基本上要更換geom_point()geom_blank() 沒問題。

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

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)")

將顏色指示恢復到legend(s)的正確方法是什么? 現在,它們僅顯示某個參數(顏色或大小)的各個級別的值,而不顯示具有特定級別的實際圖形元素(點的顏色或大小)。

如何將實際點隱藏在繪圖窗口之外? 這些方面的東西:

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

一個簡單的方法是使用size選項:

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

你能繪制兩個geom_points() - 一個背景顏色嗎?

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

最后,考慮到Aniko的建議(我最初無法工作,如此丟棄,不正常)我想出了以下代碼。

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)) 

因此,它大約就在您的數據移位,上軸,然后扣除的那部分

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM