簡體   English   中英

ggplot2-刪除R中的尺寸圖例

[英]ggplot2 - removing size legend in R

我想刪除右側的20號圖例。 下面是我的代碼:

qplot(lingLocation[ind,ind_water_fountain]/lingLocation[ind,1], 
     lingLocation[ind,ind_soda]/lingLocation[ind,1],
     color = lingLocation[ind,ind_frosting]/lingLocation[ind,1], size = 20) +
     # opts(legend.position = "none") +
     scale_colour_gradient("Frosting %", low = "blue", high = "red") +
     ylab("Soda %") +
     xlab("Water Fountain %")

謝謝!

我的情節

嘗試從qplot調用中刪除size=20參數,並將其geom_pointgeom_point調用中。

例如,將您的代碼更改為此:

qplot(lingLocation[ind,ind_water_fountain]/lingLocation[ind,1], 
     lingLocation[ind,ind_soda]/lingLocation[ind,1],
     color = lingLocation[ind,ind_frosting]/lingLocation[ind,1]) +
     # opts(legend.position = "none") +
     scale_colour_gradient("Frosting %", low = "blue", high = "red") +
     ylab("Soda %") +
     xlab("Water Fountain %") +
     geom_point(size=20)

我不使用qplot函數,但我認為應該可以。 我相信ggplot2會為每個geom中的每個美學調用增加一個比例,這就是qplot可能正在做的事情。 但是,由於將大小應用於所有點,因此將尺寸參數設置為aes之外應該會達到相同的效果,並且size=20不會為其生成圖例(我認為)。 geom_point應繼承的美學qplot (我希望)。

讓我知道這個是否奏效!

編輯:

我剛剛測試過。 將大小放在geom_point應該可以。 但是,從qplot調用時, geom_point內部的大小設置似乎與大小設置不同,因此也許可以在geom_point內部設置較小的大小來geom_point (例如geom_point(size=5) )。

qplot假定size規格是一個映射,因此會創建一個比例。 在這里,您只想將其設置為20,所以將size = 20替換為size = I(20) 這會設置大小,並且不會創建比例(並且可能會使點比您預期的要大)。

暫無
暫無

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

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