R 用多行区分线型
我想将其保存在R 用多行区分线型,r,ggplot2,R,Ggplot2,我想将其保存在geom_line()中,并尝试区分不同的线型 Var1 Var2 Freq Week 1 A2 Status Yet to Attempt 9 45 2 A3 Status Yet to Attempt 9 45 3 A4 Udemy Status Yet to Attempt 6 45 4 A5 Status Yet to Attempt 9 45 5 A2 Status
geom_line()
中,并尝试区分不同的线型
Var1 Var2 Freq Week
1 A2 Status Yet to Attempt 9 45
2 A3 Status Yet to Attempt 9 45
3 A4 Udemy Status Yet to Attempt 6 45
4 A5 Status Yet to Attempt 9 45
5 A2 Status Yet to Attempt 11 46
6 A3 Status Yet to Attempt 9 46
7 A4 Udemy Status Yet to Attempt 8 46
8 A5 Status Yet to Attempt 11 46
不幸的是,对于第1行和第8行,x和y的值是相同的。因此,我们需要更改线型以进行区分。若要将线型设置为常量,请使用
linetype
geom参数(例如,geom\u line(data=d,mapping=aes(x=x,y=y),linetype=3)
将层中所有线的线型设置为3,对应于虚线)
您可以将
线型设置为如下所示:
ggplot(df,aes(x=week,y=Freq) + geom_line(aes(col=Var1))..
由于您的示例数据很难输入到R中,下面是一个使用mtcars
数据集的示例:
ggplot(df,aes(x=week,y=Freq) + geom_line(aes(linetype=Var1))..
ggplot(mtcars, aes(x=mpg, y=disp)) +
geom_line(aes(linetype=as.factor(cyl)))