ggplot2: show missing value colour in legend

眉间皱痕 提交于 2019-11-28 02:02:10

Workaround for the problem would be to replace NA values in your data with same other character (for example, unknown) and plot data.

So, made new variable vore2 that has vore values as characters. Then replaced NA values with the unknown.

msleep$vore2<-as.character(msleep$vore)
msleep$vore2[is.na(msleep$vore2)]<-"unknown"

In the plot used new variable vore2 for the colors.

p <- qplot(sleep_total, sleep_cycle, data=msleep, colour=vore2)
p +  scale_colour_hue("What does \nit eat?", 
            breaks=c("herbi", "carni", "omni", "insecti", "unknown"), 
                labels=c("plants", "meat", "both", "insects", "don't know"))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!