R语言21-多变量绘图

在原来两个变量的图里面再加一个变量 试图增加颜色,以此来表现

eg1:color=gender用包裹器放在geom_line里面

ggplot(aes(x=age,y=friend_count),data = subset(pf,is.na(gender)))+
  geom_line(aes(color = gender),stat = 'summary',fun.y = median)

R语言21-多变量绘图_第1张图片
eg2:color=creditlevel置于ggplot的包裹器里

ggplot(aes(x=BankcardUtilization,y=StatedMonthlyIncome,color=creditlevel),data = subset(data,!(is.na(data$creditlevel))))+
  geom_jitter(alpha=0.5)+scale_y_continuous(limits =c(0,50000))+
  scale_x_continuous(limits = c(0,2))+
  facet_wrap(~IsBorrowerHomeowner)+scale_color_brewer(type = "seq")+
  theme(panel.background = element_rect(fill="#DCDCDC"),
        panel.grid = element_blank())+
  ggtitle("信用等级影响因素分析")

scale_colour_brewer:调整色标颜色

调整绘图色标:

  1. scale_colour_brewer:https://ggplot2.tidyverse.org/reference/scale_brewer.html
  2. ColorBrewer 调色板和安全色:http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/#palettes-color-brewer
  3. Legends:http://www.cookbook-r.com/Graphs/Legends_(ggplot2)/

你可能感兴趣的:(R语言整理(极简版))