R语言使用ggplot绘制点线和区域,并亲自为之着色
将点的尺寸设置成5,shape设置成21,再把线和点着色,就得到如下效果:
# Load plyr so we can use ddply() to create the example data set
library(plyr)
library(tidyverse)
ggplot(BOD, aes(x=Time, y=demand)) +
geom_line(size=1, shape=22,color='cyan') +
geom_point(size=5, shape=21, colour="brown", fill="violet")

使用参考文献的数据集,设置线型的颜色为褐色,点的尺寸为5,shape为21,并将点的颜色设置成青色和金麒麟色,效果如下,position_dodge的值主要用来调整两条线之间的间距。
# Load plyr so we can use ddply() to create the example data set
library(plyr)
library(tidyverse)
# Summarize the ToothGrowth data
tg <- ddply(ToothGrowth, c("supp", "dose"), summarise, length=mean(len))
# Save the position_dodge specification because we'll use it multiple times
pd <- position_dodge(0.2)
ggplot(tg, aes(x=dose, y=length, fill=supp)) +
geom_line(position=pd,colour='brown') +
geom_point(shape=21, size=5, position=pd) +
scale_fill_manual(values=c("cyan","goldenrod"))

笔者主要为area设置了填充色和边框色,分别为金麒麟色和青色
# Load plyr so we can use ddply() to create the example data set
library(plyr)
library(tidyverse)
sunspotyear <- data.frame(
Year = as.numeric(time(sunspot.year)),
Sunspots = as.numeric(sunspot.year)
)
ggplot(sunspotyear, aes(x=Year, y=Sunspots)) + geom_area(color='cyan',fill='goldenrod')

为区域和线添加点
ggplot(sunspotyear, aes(x=Year, y=Sunspots)) + geom_area(color='cyan',fill='goldenrod')+geom_point()

参考文献:Practical Receipes for Visualizing Data----R Graphics Cookbook —Winston Chang O’REILLY
- 点赞
- 收藏
- 关注作者
评论(0)