[英]R: adding a plot legend in R
正如@rawr所說, palette()
決定了使用的顏色順序。 如果使用整數指定顏色,它也會查看palette()
。 從而
with(iris,plot(Sepal.Length, Sepal.Width, col = Species))
legend("topright",legend=levels(iris$Species),col=1:3, pch=1)
很好地工作。
Base R沒有自動圖例功能: ggplot2
包有。
library(ggplot2)
ggplot(iris,aes(Sepal.Length,Sepal.Width,colour=Species))+geom_point()
為您提供帶有自動圖例的theme_set(theme_bw())
如果您不喜歡灰色背景,請使用theme_set(theme_bw())
)。
內置的lattice
包也可以做自動圖例:
library(lattice)
xyplot(Sepal.Width~Sepal.Length,group=Species,data=iris,auto.key=TRUE)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.