R 如何制作不同尺寸的单线
我有以下样本数据:R 如何制作不同尺寸的单线,r,ggplot2,R,Ggplot2,我有以下样本数据: head(output.melt,10) month variable value LineSize 1 01 1997 100.00000 1 2 02 1997 91.84783 1 3 03 1998 92.67626 1 4 04 1998 105.70113 1 5 05 1998 115.12516
head(output.melt,10)
month variable value LineSize
1 01 1997 100.00000 1
2 02 1997 91.84783 1
3 03 1998 92.67626 1
4 04 1998 105.70113 1
5 05 1998 115.12516 1
6 06 1998 118.95298 1
7 07 1999 117.99673 1
8 08 1999 125.50852 1
9 09 1999 119.39502 1
10 10 1999 100.79032 1
11 03 Mean 103.17473 2
12 04 Mean 108.12440 2
13 05 Mean 109.54016 2
14 06 Mean 107.71431 2
15 07 Mean 107.86694 2
16 08 Mean 108.32371 2
17 09 Mean 102.06684 2
18 10 Mean 99.96975 2
19 11 Mean 111.94529 2
20 12 Mean 113.49491 2
我想绘制一个图,其中一行具有不同的线型
和大小
。我得到的是不同的线型
,但不是大小
:
theplot=ggplot(data = output.melt, aes(x=month, y=value,colour=variable,group=variable,linetype = LineSize))
+geom_line()
+scale_linetype( guide="none")
+ggtitle(as.character("Hello"))+theme_economist()
但是上面的代码并没有使线条(其中LineSize
等于2)比其他线条宽,这是我想要的。将size=LineSize
添加到aes会创建一个丑陋的图形。
正如评论中所建议的,您必须使用以下代码:
theplot=ggplot(data = output.melt, aes(x=month, y=value,colour=variable,group=variable, size= as.numeric(LineSize)))
+geom_line()
+scale_linetype( guide="none")
+ggtitle(as.character("Hello"))
请记住,a
size=2的大小相当大,因此您必须调整表 正如评论中所建议的,您必须使用以下代码:
theplot=ggplot(data = output.melt, aes(x=month, y=value,colour=variable,group=variable, size= as.numeric(LineSize)))
+geom_line()
+scale_linetype( guide="none")
+ggtitle(as.character("Hello"))
请记住,asize=2的大小相当大,因此您必须调整表 实际上,您指定的是线型,而不是大小linetype=LineSize
。尝试将其替换为size=LineSize
@C.Square无法正常工作<代码>警告消息:不建议对离散变量使用大小。
我认为您应该将geom\u行(大小=行大小)
@Aneconomist然后我得到了错误:提供给连续缩放的离散值
@Roland请给出答案,因为现在我得到的是丑陋的图形只有你的解决方案:/你确实在指定线型而不是大小linetype=LineSize
。尝试将其替换为size=LineSize
@C.Square无法正常工作<代码>警告消息:不建议对离散变量使用大小。
我认为您应该将geom\u行(大小=行大小)
@Aneconomist然后我得到了错误:离散值提供给连续比例
@Roland请给出一个答案,因为现在我只能用你的解决方案得到难看的图形:/这个效果更好:theplot=ggplot(data=output.melt,aes(x=month,y=value,color=variable,group=variable,size=LineSize))+geom\u line(aes(linetype=LineSize))+scale_size_manual(values=c(3,1),guide=“none”)+ggtitle(as.character(names(“Hello”))
这更有效:theplot=ggplot(data=output.melt,aes(x=month,y=value,color=variable,group=variable,size=LineSize))+geom_line(aes(linetype=LineSize))+scale_size_manual(values=c(3,1),guide=“none”)+ggtitle(as.character(names(“Hello”))