This article describes how to create a line plot using the ggplot2 R package You will learn how to: Create basic and grouped line plots Add points to a line plot Change the line types and colors by group Contents: Key R functions Key functions: geom_path()connects the observations in the...
library(ggplot2) # Basic line plot with points ggplot(data=df, aes(x=dose, y=len, group=1)) + geom_line()+ geom_point() # Change the line type ggplot(data=df, aes(x=dose, y=len, group=1)) + geom_line(linetype = "dashed")+ geom_point() # Change the color ggplot(data=...
良好的扩展性:tidyplot 与ggplot2 兼容,用户可以在 tidyplot 中使用 add() 函数,灵活地加入 ggplot2 的图层和功能,可以在简洁的框架下结合 ggplot2 的强大功能,实现复杂的可视化需求。 温馨提示:若页面不能正常显示数学公式和代码,请阅读原文获得更好的阅读体验。 阅读全文:tidyplots:跟 ggplot2 说再见吧! (lia...
ggplot(dat, aes(x=cond, y=rating, fill=cond)) + geom_boxplot() 3.17、不同变量填充不同色箱图、无图例 ggplot(dat, aes(x=cond, y=rating, fill=cond)) + geom_boxplot() + guides(fill=FALSE) 3.18、水平箱图 ggplot(dat, aes(x=cond, y=rating, fill=cond)) + geom_boxplot() + gui...
# 添加字体font.add('SimSun','simsun.ttc')# Modify theme components# 修改主题gg+theme(# 设置标题plot.title=element_text(size=20,# 字体大小face="bold",# 字体加粗family="SimSun",# 字体类型color="tomato",# 字体颜色hjust=0.5,# 标题离左边距距离lineheight=1.2),# 线条高度# 设置子标题plot....
p2<-ggplot(mydata)+geom_hline(yintercept=-mean(mydata$B),linetype=2,size=.25,colour="grey")+geom_bar(aes(x=id,y=-B),stat="identity",fill="#C44E4C",colour=NA)+ylim(-40,0)+scale_x_reverse()+geom_text(aes(x=id,y=-B-1.75,label=paste0(B,"%")),size=4.5,family="myfont...
ggplot2是由Hadley Wickham创建的一个十分强大的可视化R包。按照ggplot2的绘图理念,Plot(图)= data(数据集)+ Aesthetics(美学映射)+ Geometry(几何对象): data: 数据集,主要是data frame; Aesthetics: 美学映射,比如将变量映射给x,y坐标轴,或者映射给颜色、大小、形状等图形属性; ...
geom_line(): 线图 geom_bar(): 条形图 箱线图 e+geom_boxplot() 1. 添加有缺口的箱线图 e+geom_boxplot(notch = TRUE) 1. 按dose分组映射给颜色 e+geom_boxplot(aes(color=dose)) 1. 将dose映射给填充颜色 e+geom_boxplot(aes(fill=dose)) 1. 按supp进行分类并映射给填充颜色 ggplot(ToothGrow...
element_line(colour = “gray”), plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5) ) + ylab(“”) + xlab(“”)Note that I saved everything except the original graph’s first ggplot() line of code to the custom geom.Here’s how simple...
add = "mean_se", error.plot = "upper_errorbar") p14 1 2 3 4 # Change error.plot to "pointrange" p15 <- ggbarplot(df3, x = "dose", y = "len", add = "mean_se", error.plot = "pointrange") p15 1 2 3 4 # Ad...