R语言绘制区域,自主加上若干个函数,并设置其中的参数属性值,绘制出图形。
笔者在原著的基础上加了geom_jitter(),效果如下:
# 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(colour="black", fill="blue", alpha=.2)+geom_jitter()

笔者在上图基础上设置了Jitter的颜色为青色,效果如下:
ggplot(sunspotyear, aes(x=Year, y=Sunspots)) +
geom_area(colour="black", fill="blue", alpha=.2)+geom_jitter(colour="cyan")

笔者在上图基础上加了geom_polygon()效果如下:
ggplot(sunspotyear, aes(x=Year, y=Sunspots)) +
geom_area(colour="black", fill="blue", alpha=.2)+geom_jitter(colour="cyan")+geom_polygon()

在geom_polygon函数内部设置填充色为蓝色
ggplot(sunspotyear, aes(x=Year, y=Sunspots)) +
geom_area(colour="black", fill="blue", alpha=.2)+geom_jitter(colour="cyan")+geom_polygon(fill="blue")

笔者在原有的基础上加了geom_rug(),效果如下:
ggplot(sunspotyear, aes(x=Year, y=Sunspots)) +
geom_area(colour="black", fill="blue", alpha=.2)+geom_jitter(colour="cyan")+geom_rug()

笔者为图形分布加上geom_smooth()函数,并设置公式和方法,分别为y~x,loess
# 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(colour="black", fill="blue", alpha=.2)+geom_jitter(colour="cyan")+geom_rug()+geom_smooth(method='loess',formula=y~x)效果如下:

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