更改线图大小,了解大小参数如何工作 [英] Change size of a line plot, understand how the size argument works

查看:110
本文介绍了更改线图大小,了解大小参数如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作带有错误条的多行图。如果我不使用 size 参数,则一切正常:

 #sample data 
Response = runif(4)
ResponseMin = Response-Response / 5
ResponseMax = Response + Response / 5
Cases = rep(c(Case1, case2),each = 2)
df = data.frame(x = 1:2,Average = Response,Lower = ResponseMin,Upper = ResponseMax,Case = Cases)
#let's plot
library(ggplot2)
ggplot(df,aes(x = x,y = Average,color = Case))+
geom_line(aes(group = Case))+
geom_point )+
geom_errorbar(aes(ymin = Lower,ymax = Upper,width = 0.25))+
labs(y =foo,title =Some plot fu)



然而,当我修改线的大小,我开始变得奇怪的东西:

  ggplot(df,aes(x = x,y =平均,color = Case))+ 
geom_line(aes(group = Case,size = 1))+
geom_point( )+
geom_errorbar(aes(ymin = Lower,ymax = Upper,width = 0.25))+
labs(y =foo,title =Some plot fu)



为什么额外的图例条目为1?当我为errobars添加一个 size 参数时,无论 size 是:

  ggplot(df,aes(x = x,y = Average,color = Case))+ 
geom_line(aes(ymin = Lower,ymax = Upper,width = 0.25,size = 1)geom_line()(aes(group = Case,size = 1))+
geom_point()+
geom_errorbar )+
labs(y =foo,title =一些情节)

  ggplot(df,aes(x = x,y = Average ,color = Case))+ 
geom_line(aes(group = Case,size = 2))+
geom_point()+
geom_errorbar(aes(ymin = Lower,ymax = Upper,width = 0.25,size = 2))+
labs(y =foo,title =Some plot fu)



你能帮我弄清楚这里发生了什么吗?如果你在 aes 中设置 size ,你将它映射到一个变量

 `1` = 1 

和ggplot2创建一个图例。如果您只想设置尺寸,您可以在 aes 之外做到这一点:

  geom_line(aes(group = Case),size = 1)


I'm making a multiple lines plot with errorbars. If I don't use the size argument, everything is fine:

# sample data
Response=runif(4)
ResponseMin=Response-Response/5
ResponseMax=Response+Response/5 
Cases=rep(c("Case1","Case2"),each=2)    
df=data.frame(x=1:2,Average=Response,Lower=ResponseMin,Upper=ResponseMax,Case=Cases)
# let's plot
library(ggplot2)
ggplot(df,aes(x=x,y=Average,colour=Case)) +
geom_line(aes(group=Case)) + 
geom_point() +
geom_errorbar(aes(ymin=Lower,ymax=Upper,width=0.25)) +
labs(y="foo",title="Some plot fu")

However, when I modify the line size, I start getting weird stuff:

ggplot(df,aes(x=x,y=Average,colour=Case)) +
geom_line(aes(group=Case, size = 1)) + 
geom_point() +
geom_errorbar(aes(ymin=Lower,ymax=Upper,width=0.25)) +
labs(y="foo",title="Some plot fu")

Why the extra legend entry "1"? And when I add a size argument for the errobars, it looks like the size of the lines stays the same, whatever the value of size is:

ggplot(df,aes(x=x,y=Average,colour=Case)) +
geom_line(aes(group=Case, size = 1)) + 
geom_point() +
geom_errorbar(aes(ymin=Lower,ymax=Upper,width=0.25, size = 1)) +
labs(y="foo",title="Some plot fu")

ggplot(df,aes(x=x,y=Average,colour=Case)) +
geom_line(aes(group=Case, size = 2)) + 
geom_point() +
geom_errorbar(aes(ymin=Lower,ymax=Upper,width=0.25, size = 2)) +
labs(y="foo",title="Some plot fu")

Can you help me figure out what's happening here?

解决方案

If you set size inside aes you are mapping it to a variable

`1` = 1

and ggplot2 creates a legend. If you just want to set the size, you can do that outside of aes:

geom_line(aes(group=Case), size = 1)

这篇关于更改线图大小,了解大小参数如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆