1. 水平和垂直线 rm(list=ls())library(ggplot2)# Simple scatter plotsp<-ggplot(data=mtcars,aes(x=wt,y=mpg))+geom_point()# Add horizontal line at y = 2Osp+geom_hline(yintercept=20)# Change line type and colorsp+geom_hline(yintercept=20,linetype="dashed",color="red")# Change li...
theme(panel.grid.major = element_line(size = .5, linetype = "dashed"), panel.grid.minor = element_line(size = .25, linetype = "dotted"), panel.grid.major.x = element_line(color = "red1"), panel.grid.major.y = element_line(color = "blue1"), panel.grid.minor.x = element_...
(ggplot2) # 创建数据集 data <- data.frame( x = 1:10, y = rnorm(10) ) # 绘制散点图并添加水平线 ggplot(data, aes(x = x, y = y)) + geom_point() + geom_hline(yintercept = 0, linetype = "dashed", color = "red") + labs(title = "Scatter Plot with Horizontal Line", ...
theme(legend.position = "bottom", legend.direction = "horizontal", legend.title = element_blank()) p7_1 # 2) 使用经济学角度的图片可视化 p7_2 <- ggplot(data = exports_data, aes(x = year, y = export, colour = product)) + geom_line(size = 1.5) + scale_x_continuous(breaks ...
Line types Themes and background colors Axis scales and transformations Axis ticks: customize tick marks and labels, reorder and select items Add straight lines to a plot: horizontal, vertical and regression lines Rotate a plot: flip and reverse ...
Add a comment 1 vote I think that it looks better if stat_boxplot(geom ='errorbar') on the first line as it hides the vertical line. bp <- ggplot(iris, aes(factor(Species), Sepal.Width, fill = Species))+ stat_boxplot(geom ='errorbar') bp + geom_boxplot() Share Cite ...
element_line():同样element_line()用于修改基于线的组件,例如轴线,主要和次要网格线等。 element_rect():修改矩形组件,例如绘图和面板背景。 element_blank():关闭显示主题项目。 有关更多信息,请参见即将进行的讨论。让我们讨论许多与更改绘图输出有关的任务,从修改标题和轴文本开始。
add = "reg.line", # Add regressin line add.params = list(color = "blue", fill = "lightgray"), # Customize reg. line conf.int = TRUE, # Add confidence interval cor.coef = TRUE, # Add correlation coefficient. see ?stat_cor
Add a comment 1 Answer Sorted by: 5 Use text with the indicated arguments. Alternately use the legend function as shown. abline is classic graphics so it is assumed you want to use that plotting system but if you want ggplot2 see Add a horizontal line to pl...
Normally, if you add a line, it will appear in all facets. # Facet, based on condspf<-sp+facet_grid(.~cond)spf# Draw a horizontal line in all of the facets at the same valuespf+geom_hline(aes(yintercept=10)) If you want the different lines to appear in the different facets, ...