R ggplot2:修改图例';散点图{ggplot2}中两个因子的s元素?

R ggplot2:修改图例';散点图{ggplot2}中两个因子的s元素?,r,plot,ggplot2,legend-properties,R,Plot,Ggplot2,Legend Properties,我希望散点图显示两个因素:点大小和灰色阴影: a1<-c(seq(1,10,1)) a2<-c(seq(11,20,1)) a3<-c(rep(c(1,2),each = 5)) a4<-c(rep(c(5,10,15,20,25),2)) df<-data.frame(a1,a2,a3,a4) t1<-theme( plot.background = element_blank(), panel.grid.major = ele

我希望散点图显示两个因素:点大小和灰色阴影:

a1<-c(seq(1,10,1))
a2<-c(seq(11,20,1))
a3<-c(rep(c(1,2),each = 5))
a4<-c(rep(c(5,10,15,20,25),2))

df<-data.frame(a1,a2,a3,a4)

t1<-theme(        
  plot.background = element_blank(), 
  panel.grid.major = element_blank(), 
  panel.grid.minor = element_blank(), 
  panel.border = element_blank(), 
  panel.background = element_blank(),
  axis.line = element_line(size=.4))

ggplot(df, aes(x= a1, y= a2)) + 
  geom_point(aes(alpha=factor(a3), size = factor(a4))) + t1 + labs(x = "x label", y = "y label") +
  theme(legend.background = element_rect())

a1基于@user20650和@inscaven的建议以及更多的谷歌搜索,我希望更好地了解ggplot是如何组织的以及如何生成我的plot:

# dummy data
a1<-c(seq(1,10,1))
a2<-c(seq(11,20,1))
a3<-c(rep(c(1,2),each = 5))
a4<-c(rep(c(5,10,15,20,25),2))

# create data frame 
df<-data.frame(a1,a2,a3,a4)

# set nice theme  
t1<-theme(        
  plot.background = element_blank(), 
  panel.grid.major = element_blank(), 
  panel.grid.minor = element_blank(), 
  panel.border = element_blank(), 
  panel.background = element_blank(),
  axis.line = element_line(size=.4))

# create scatter plot
ggplot(df, aes(x= a1, y= a2)) +                             # create basic plot
  geom_point(aes(size = factor(a4), colour = factor(a3))) + # colour has to be inside of aes !! (ASSIGNED = MAPPED)
  scale_colour_grey(name = "Set second\nline in title") +   # change title of 1st legend, change colours 
  scale_size_discrete(name = "Name by size") +              # change title of 2nd legend, size of point has been already assigned
  theme(legend.key = element_blank()) +                     # delete grey boxes around the legend
  labs(x = "x label", y = "y label") +                      # set labels on x and y  axes
  t1                                                        # add nice theme
#虚拟数据

1您不需要更改形状,因此无需缩放形状
。。。但是你不改变字母和大小刻度你说的“你传奇的背景”是什么意思?也许钥匙周围的灰色盒子?然后您需要
legend.key=element\u blank()
谢谢您的建议!我已经根据它添加了我的答案。。。