Scatter plot with linear regression line of best fit 图1,显示不同类别 df <- ggplot2::mpg %>% setDT() df_select <- df[cyl %in% c(4,8),] %>% .[,cyl:=as.factor(cyl)] cyl_color <- c("#1f77b4", "#ff983e") # geom_smooth的填充范围,只有数据和全图可选,而且se只会按垂直方向...
ggplot(dat, aes(x=cond, y=rating)) + geom_boxplot() 3.16、不同变量填充不同色箱图、图例 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...
第一选择一定是散点图(Whenever you want to understand the nature of relationship between two variables, invariably the first choice is the scatterplot);ggplot2中用来画散点图的函数是geom_point(),同时可以用geom_smooth()函数添加拟合
# Scatter plot sp <- ggplot(df, aes(x=wt, y=mpg))+ geom_point() # Add text, change colors by groups sp + geom_text(aes(label = rownames(df), color = cyl), size = 3, vjust = -1) 1. 2. 3. 4. 5. # Add text at a particular coordinate sp + geom_text(x = 3, y ...
# loess method: local regression fitting p3 <- ggscatter(df, x = "wt", y = "mpg", add = "loess", conf.int = TRUE, cor.coef = TRUE, # Add correlation coefficient. see ?stat_cor cor.coeff.args = list(method = "spearma...
add regression line to scatter plot in rggplot2 http://www.cookbook-r.com/Graphs/Scatterplots_(ggplot2)/ http://stackoverflow.com/questions/7549694/ggplot2-adding-regression-line-equation-and-r2-on-graph 然后我只看了这两个链接而已,就得到了自己想要的图!
ggp+# Draw multiple line segmentsgeom_segment(data=data_lines, aes(x=x, y=y, xend=xend, yend=yend, col=col)) After running the previously shown R syntax the ggplot2 scatterplot shown in Figure 4 has been drawn. As you can see, we have added three lines with different colors and ...
To add a regression line on a scatter plot, the functiongeom_smooth()is used in combination with the argumentmethod = lm.lmstands for linear model. p <- ggplot(cars, aes(speed, dist)) + geom_point()# Add regression linep + geom_smooth(method = lm)# loess method: local regression ...
ggplot2是由Hadley Wickham创建的一个十分强大的可视化R包。按照ggplot2的绘图理念,Plot(图)= data(数据集)+ Aesthetics(美学映射)+ Geometry(几何对象): data: 数据集,主要是data frame; Aesthetics: 美学映射,比如将变量映射给x,y坐标轴,或者映射给颜色、大小、形状等图形属性; ...
线(line,vline,abline,hline,stat_function等):一般是基于函数来处理位置 射(segment):特征是指定位置有xend和yend,表示射线方向 面(tile, rect):这类一般有xmax,xmin,ymax,ymin指定位置 棒(boxplot,bin,bar,histogram):往往是二维或一维变量,具有width属性 ...