ggplot(linetypes, aes(0, y)) + geom_segment(aes(xend = 5, yend = y, linetype = lty)) + scale_linetype_identity() + geom_text(aes(label = lty), hjust = 0, nudge_y = 0.2) +scale_x_continuous(NULL, breaks = NULL) + scale_y_reverse(NULL, breaks = NULL) 使用名称直接指定...
p <-ggplot(df2, aes(x=dose,y=len,group=supp))# 不同组不同线的类型和点的形状p + geom_line(aes(linetype = supp)) +geom_point(aes(shape = supp))# 增加颜色p + geom_line(aes(linetype=supp,color = supp))+geom_point(aes(shape=supp,color = supp))# 手动设置颜色p + geom_line(a...
ggplot(economics, aes(x=date)) + geom_line(aes(y = psavert), color = "darkred") + geom_line(aes(y = uempmed), color="steelblue", linetype="twodash") + theme_minimal()require(reshape2)df <- melt(economics[, c("date", "psavert", "uempmed")], id="date")ggplot(df,...
Uselinetypeandsizearguments in ggplot2 : # Create some datax <-1:10; y1 <- x*x; y2 <-2*y1 df <- data.frame( x = c(x, x), y = c(y1, y2), grp = as.factor(rep(c("A","B"), each =10)) )# Plotlibrary(ggplot2) ggplot(data = df, aes(x, y, group = grp))...
ggplot(aes(date, value01, group = variable)) + geom_line(aes(colour = value01), linetype = 2) 2. 参考线 为图形添加参考线对图形的注释非常有用,主要有水平、竖直和对角线三种参考线,对应于三个函数: geom_hline:yintercept(y轴截距)
library(ggplot2) 1. 创建ggplot对象,并设置x轴和y轴变量,同时设置linetype和shape参数为group变量。这里的data是数据集的名称,x和y是数据集中的两个变量名称,group是用于设置linetype和shape的变量名称。使用以下代码创建ggplot对象: ggplot(data,aes(x,y,linetype=group,shape=group)) ...
library(ggplot2) 主要函数及参数 · Key functions: geom_line(), geom_step(), geom_path() · Key arguments to customize the plot: alpha, color, linetype and size. 绘图数据 df <- data.frame(dose=c("D0.5","D1","D2"),len=c(4.2, 10, 29.5))head(df) ...
2. 完整代码如下: data<-data.frame(x=1:10,y1=1:10,y2=11:20)p<-ggplot(data,aes(x=x,y=y1))p<-p+geom_blank()+scale_y_continuous(sec.axis=sec_axis(~.,name="y2"))p<-p+geom_line(aes(y=y1))p<-p+geom_line(aes(y=y2),linetype="dashed",color="red")p<-p+xlab("x轴...
linetype="dashed") Example 3: Add Multiple Line Segments to ggplot2 Plot It is also possible to append multiple line segments to a ggplot2 plot. For this, it makes sense to define all the parameters of our lines in a data frame object first: ...
The problem is that we haven’t specified that the lines should be grouped by transmission, so it’s just using the already provided number of cylinders. To handle this, we assign thegroupandlinetypeaesthetics to our second categorical variable,am. Note thatgroupis handled inggplot, butlinetyp...