鑒于以下代碼,我無法理解為什么圖例沒有改變。使用 geom_histogram 可以使用相同的選項。在此先感謝您的幫助。
data(mtcars)
ggplot(mtcars, aes(x = disp, color = as.factor(am)))
geom_density(aes(group = am))
theme_classic()
guides(fill = guide_legend(reverse=TRUE))
labs(x = "Displacement", y = "Density")
scale_fill_manual(name="",values=c("black","gray"),labels=c("Foreign","Domestic"))
uj5u.com熱心網友回復:
您color在呼叫aes(). 要修改此變數的比例,您需要使用scale_color_manual而不是scale_fill_manual。
這很棘手,因為geom_histogram確實使用fill,但geom_density使用color.
作業解決方案:
data(mtcars)
ggplot(mtcars, aes(x = disp, color = as.factor(am)))
geom_density(aes(group = am))
theme_classic()
guides(fill = guide_legend(reverse=TRUE))
labs(x = "Displacement", y = "Density")
scale_color_manual(name="",values=c("black","gray"),labels=c("Foreign","Domestic"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/387231.html
