簡體   English   中英

使用 ggplot2 更改密度圖中圖例的形狀

[英]Change the shape of the legend in density plots with ggplot2

我想將密度圖圖例中顯示的框更改為線條,並且我知道我需要使用指南。 但是,以下代碼不起作用:

set.seed(0)    
df <- data.frame(Income=c(rnorm(500,1000,200),rnorm(500,900,10)),Type=c(rep("A",500),rep("K",500)))
p2p <- ggplot(df,aes(x=Income))+geom_density(aes(colour=Type))+
guides(colour = guide_legend(override.aes = list(linetype = 1, shape = 3)))

你在尋找這樣的東西嗎?

ggplot(df,aes(x=Income))+ 
  geom_density(aes(colour=Type),show_guide=FALSE)+
  stat_density(aes(x=Income, colour=Type), 
               geom="line",position="identity")

在此處輸入圖片說明

暫無
暫無

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

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