如何添加纹理以填充ggplot 2中的颜色

如何添加纹理以填充ggplot 2中的颜色

我现在用scale_brewer()对于填充和这些看起来漂亮的颜色(在屏幕上和通过彩色打印机),但打印相对均匀的灰色时,使用黑白打印机。我在网上搜索ggplot2文档,但是没有看到任何关于添加纹理来填充颜色的信息。有没有官员ggplot2如何做到这一点,或谁有黑客,他们使用?所谓纹理,我指的是像对角线条,反向对角线条,点图案,等等,这将区分填充颜色时,打印在黑色和白色。



红颜莎娜
浏览 2362回答 3
3回答

慕少森

嘿,伙计们,这里有一个小黑客,用一种非常基本的方式来解决纹理问题:gggplot 2:使一个条形图的边框比使用R的条形图的边框更暗编辑:我终于有时间给出这个黑客的一个简单例子,它允许在ggplot 2中至少有3种基本模式。守则:Example.Data<-&nbsp;data.frame(matrix(vector(),&nbsp;0,&nbsp;3,&nbsp;dimnames=list(c(),&nbsp;c("Value",&nbsp;"Variable",&nbsp;"Fill"))),&nbsp;stringsAsFactors=F)Example.Data[1,&nbsp;]&nbsp;<-&nbsp;c(45,&nbsp;'Horizontal&nbsp;Pattern','Horizontal&nbsp;Pattern'&nbsp;)Example.Data[2,&nbsp;]&nbsp;<-&nbsp;c(65,&nbsp;'Vertical&nbsp;Pattern','Vertical&nbsp;Pattern'&nbsp;)Example.Data[3,&nbsp;]&nbsp;<-&nbsp;c(89,&nbsp;'Mesh&nbsp;Pattern','Mesh&nbsp;Pattern'&nbsp;)HighlightDataVert<-Example.Data[2,&nbsp;]HighlightHorizontal<-Example.Data[1,&nbsp;]HighlightMesh<-Example.Data[3,&nbsp;]HighlightHorizontal$Value<-as.numeric(HighlightHorizontal$Value)Example.Data$Value<-as.numeric(Example.Data$Value)HighlightDataVert$Value<-as.numeric(HighlightDataVert$Value)HighlightMesh$Value<-as.numeric(HighlightMesh$Value)HighlightHorizontal$Value<-HighlightHorizontal$Value-5HighlightHorizontal2<-HighlightHorizontal HighlightHorizontal2$Value<-HighlightHorizontal$Value-5HighlightHorizontal3<-HighlightHorizontal2 HighlightHorizontal3$Value<-HighlightHorizontal2$Value-5HighlightHorizontal4<-HighlightHorizontal3 HighlightHorizontal4$Value<-HighlightHorizontal3$Value-5HighlightHorizontal5<-HighlightHorizontal4 HighlightHorizontal5$Value<-HighlightHorizontal4$Value-5HighlightHorizontal6<-HighlightHorizontal5 HighlightHorizontal6$Value<-HighlightHorizontal5$Value-5HighlightHorizontal7<-HighlightHorizontal6 HighlightHorizontal7$Value<-HighlightHorizontal6$Value-5HighlightHorizontal8<-HighlightHorizontal7 HighlightHorizontal8$Value<-HighlightHorizontal7$Value-5HighlightMeshHoriz<-HighlightMesh HighlightMeshHoriz$Value<-HighlightMeshHoriz$Value-5HighlightMeshHoriz2<-HighlightMeshHoriz HighlightMeshHoriz2$Value<-HighlightMeshHoriz2$Value-5HighlightMeshHoriz3<-HighlightMeshHoriz2 HighlightMeshHoriz3$Value<-HighlightMeshHoriz3$Value-5HighlightMeshHoriz4<-HighlightMeshHoriz3 HighlightMeshHoriz4$Value<-HighlightMeshHoriz4$Value-5HighlightMeshHoriz5<-HighlightMeshHoriz4 HighlightMeshHoriz5$Value<-HighlightMeshHoriz5$Value-5HighlightMeshHoriz6<-HighlightMeshHoriz5 HighlightMeshHoriz6$Value<-HighlightMeshHoriz6$Value-5HighlightMeshHoriz7<-HighlightMeshHoriz6 HighlightMeshHoriz7$Value<-HighlightMeshHoriz7$Value-5HighlightMeshHoriz8<-HighlightMeshHoriz7 HighlightMeshHoriz8$Value<-HighlightMeshHoriz8$Value-5HighlightMeshHoriz9<-HighlightMeshHoriz8 HighlightMeshHoriz9$Value<-HighlightMeshHoriz9$Value-5HighlightMeshHoriz10<-HighlightMeshHoriz9 HighlightMeshHoriz10$Value<-HighlightMeshHoriz10$Value-5HighlightMeshHoriz11<-HighlightMeshHoriz10 HighlightMeshHoriz11$Value<-HighlightMeshHoriz11$Value-5HighlightMeshHoriz12<-HighlightMeshHoriz11 HighlightMeshHoriz12$Value<-HighlightMeshHoriz12$Value-5HighlightMeshHoriz13<-HighlightMeshHoriz12 HighlightMeshHoriz13$Value<-HighlightMeshHoriz13$Value-5HighlightMeshHoriz14<-HighlightMeshHoriz13 HighlightMeshHoriz14$Value<-HighlightMeshHoriz14$Value-5HighlightMeshHoriz15<-HighlightMeshHoriz14 HighlightMeshHoriz15$Value<-HighlightMeshHoriz15$Value-5HighlightMeshHoriz16<-HighlightMeshHoriz15 HighlightMeshHoriz16$Value<-HighlightMeshHoriz16$Value-5HighlightMeshHoriz17<-HighlightMeshHoriz16 HighlightMeshHoriz17$Value<-HighlightMeshHoriz17$Value-5ggplot(Example.Data,&nbsp;aes(x=Variable,&nbsp;y=Value,&nbsp;fill=Fill))&nbsp;+&nbsp;theme_bw()&nbsp;+&nbsp;#facet_wrap(~Product,&nbsp;nrow=1)+&nbsp;#Ensure&nbsp;theme_bw&nbsp;are&nbsp;there&nbsp;to&nbsp;create&nbsp;borders &nbsp;&nbsp;theme(legend.position&nbsp;=&nbsp;"none")+ &nbsp;&nbsp;scale_fill_grey(start=.4)+ &nbsp;&nbsp;#scale_y_continuous(limits&nbsp;=&nbsp;c(0,&nbsp;100),&nbsp;breaks&nbsp;=&nbsp;(seq(0,100,by&nbsp;=&nbsp;10)))+ &nbsp;&nbsp;geom_bar(position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;legend&nbsp;=&nbsp;FALSE)+ &nbsp;&nbsp;geom_bar(data=HighlightDataVert,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;width=0.80)+geom_bar(data=HighlightDataVert,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;width=0.60)+&nbsp;&nbsp; &nbsp;&nbsp;geom_bar(data=HighlightDataVert,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;width=0.40)+ &nbsp;&nbsp;geom_bar(data=HighlightDataVert,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;width=0.20)+ &nbsp;&nbsp;geom_bar(data=HighlightDataVert,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;width=0.0)&nbsp;+ &nbsp;&nbsp;geom_bar(data=HighlightHorizontal,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5)+ &nbsp;&nbsp;geom_bar(data=HighlightHorizontal2,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5)+ &nbsp;&nbsp;geom_bar(data=HighlightHorizontal3,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5)+ &nbsp;&nbsp;geom_bar(data=HighlightHorizontal4,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5)+ &nbsp;&nbsp;geom_bar(data=HighlightHorizontal5,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5)+ &nbsp;&nbsp;geom_bar(data=HighlightHorizontal6,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5)+ &nbsp;&nbsp;geom_bar(data=HighlightHorizontal7,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5)+ &nbsp;&nbsp;geom_bar(data=HighlightHorizontal8,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5)+ &nbsp;&nbsp;geom_bar(data=HighlightMesh,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;width=0.80)+ &nbsp;geom_bar(data=HighlightMesh,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;width=0.60)+ &nbsp;&nbsp;geom_bar(data=HighlightMesh,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;width=0.40)+ &nbsp;&nbsp;geom_bar(data=HighlightMesh,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;width=0.20)+ &nbsp;&nbsp;geom_bar(data=HighlightMesh,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;width=0.0)+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+geom_bar(data=HighlightMeshHoriz2,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz3,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz4,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz5,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz6,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz7,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz8,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz9,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz10,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz11,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz12,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz13,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz14,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz15,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz16,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")+ &nbsp;&nbsp;geom_bar(data=HighlightMeshHoriz17,&nbsp;position=position_dodge(.9),&nbsp;stat="identity",&nbsp;colour="black",&nbsp;size=.5,&nbsp;fill&nbsp;=&nbsp;"transparent")产生这种情况:这不是超级漂亮,但这是我唯一能想到的解决办法。可以看到,我提供了一些非常基本的数据。为了获得垂直线,我只需创建一个数据框架来包含我想要添加垂直线的变量,并多次重新绘制图形边框,每次减少宽度。对于水平线也做了类似的事情,但是每次重绘都需要一个新的数据框架,其中我从与感兴趣的变量关联的值中减去了一个值(在我的示例中是‘5’)。有效地降低了杆的高度。这是笨重的实现,可能有更精简的方法,但这说明了如何可以实现。网格模式是两者的结合。首先绘制垂直线,然后添加水平线设置。fill如fill='transparent'以确保不绘制垂直线。在出现模式更新之前,我希望你们中的一些人会发现这是有用的。编辑2:另外,也可以添加对角线图案。我在数据框架中添加了一个额外的变量:Example.Data[4,]&nbsp;<-&nbsp;c(20,&nbsp;'Diagonal&nbsp;Pattern','Diagonal&nbsp;Pattern'&nbsp;)然后,我创建了一个新的数据框架来保存对角线的坐标:Diag&nbsp;<-&nbsp;data.frame( &nbsp;&nbsp;x&nbsp;=&nbsp;c(1,1,1.45,1.45),&nbsp;#&nbsp;1st&nbsp;2&nbsp;values&nbsp;dictate&nbsp;starting&nbsp;point&nbsp;of&nbsp;line.&nbsp;2nd&nbsp;2&nbsp;dictate&nbsp;width.&nbsp;Each&nbsp;whole&nbsp;=&nbsp;one&nbsp;background&nbsp;grid &nbsp;&nbsp;y&nbsp;=&nbsp;c(0,0,20,20), &nbsp;&nbsp;x2&nbsp;=&nbsp;c(1.2,1.2,1.45,1.45),&nbsp;#&nbsp;1st&nbsp;2&nbsp;values&nbsp;dictate&nbsp;starting&nbsp;point&nbsp;of&nbsp;line.&nbsp;2nd&nbsp;2&nbsp;dictate&nbsp;width.&nbsp;Each&nbsp;whole&nbsp;=&nbsp;one&nbsp;background&nbsp;grid &nbsp;&nbsp;y2&nbsp;=&nbsp;c(0,0,11.5,11.5),#&nbsp;inner&nbsp;2&nbsp;values&nbsp;dictate&nbsp;height&nbsp;of&nbsp;horizontal&nbsp;line.&nbsp;Outer:&nbsp;vertical&nbsp;edge&nbsp;lines. &nbsp;&nbsp;x3&nbsp;=&nbsp;c(1.38,1.38,1.45,1.45),&nbsp;#&nbsp;1st&nbsp;2&nbsp;values&nbsp;dictate&nbsp;starting&nbsp;point&nbsp;of&nbsp;line.&nbsp;2nd&nbsp;2&nbsp;dictate&nbsp;width.&nbsp;Each&nbsp;whole&nbsp;=&nbsp;one&nbsp;background&nbsp;grid &nbsp;&nbsp;y3&nbsp;=&nbsp;c(0,0,3.5,3.5),#&nbsp;inner&nbsp;2&nbsp;values&nbsp;dictate&nbsp;height&nbsp;of&nbsp;horizontal&nbsp;line.&nbsp;Outer:&nbsp;vertical&nbsp;edge&nbsp;lines. &nbsp;&nbsp;x4&nbsp;=&nbsp;c(.8,.8,1.26,1.26),&nbsp;#&nbsp;1st&nbsp;2&nbsp;values&nbsp;dictate&nbsp;starting&nbsp;point&nbsp;of&nbsp;line.&nbsp;2nd&nbsp;2&nbsp;dictate&nbsp;width.&nbsp;Each&nbsp;whole&nbsp;=&nbsp;one&nbsp;background&nbsp;grid &nbsp;&nbsp;y4&nbsp;=&nbsp;c(0,0,20,20),#&nbsp;inner&nbsp;2&nbsp;values&nbsp;dictate&nbsp;height&nbsp;of&nbsp;horizontal&nbsp;line.&nbsp;Outer:&nbsp;vertical&nbsp;edge&nbsp;lines. &nbsp;&nbsp;x5&nbsp;=&nbsp;c(.6,.6,1.07,1.07),&nbsp;#&nbsp;1st&nbsp;2&nbsp;values&nbsp;dictate&nbsp;starting&nbsp;point&nbsp;of&nbsp;line.&nbsp;2nd&nbsp;2&nbsp;dictate&nbsp;width.&nbsp;Each&nbsp;whole&nbsp;=&nbsp;one&nbsp;background&nbsp;grid &nbsp;&nbsp;y5&nbsp;=&nbsp;c(0,0,20,20),#&nbsp;inner&nbsp;2&nbsp;values&nbsp;dictate&nbsp;height&nbsp;of&nbsp;horizontal&nbsp;line.&nbsp;Outer:&nbsp;vertical&nbsp;edge&nbsp;lines. &nbsp;&nbsp;x6&nbsp;=&nbsp;c(.555,.555,.88,.88),&nbsp;#&nbsp;1st&nbsp;2&nbsp;values&nbsp;dictate&nbsp;starting&nbsp;point&nbsp;of&nbsp;line.&nbsp;2nd&nbsp;2&nbsp;dictate&nbsp;width.&nbsp;Each&nbsp;whole&nbsp;=&nbsp;one&nbsp;background&nbsp;grid &nbsp;&nbsp;y6&nbsp;=&nbsp;c(6,6,20,20),#&nbsp;inner&nbsp;2&nbsp;values&nbsp;dictate&nbsp;height&nbsp;of&nbsp;horizontal&nbsp;line.&nbsp;Outer:&nbsp;vertical&nbsp;edge&nbsp;lines. &nbsp;&nbsp;x7&nbsp;=&nbsp;c(.555,.555,.72,.72),&nbsp;#&nbsp;1st&nbsp;2&nbsp;values&nbsp;dictate&nbsp;starting&nbsp;point&nbsp;of&nbsp;line.&nbsp;2nd&nbsp;2&nbsp;dictate&nbsp;width.&nbsp;Each&nbsp;whole&nbsp;=&nbsp;one&nbsp;background&nbsp;grid &nbsp;&nbsp;y7&nbsp;=&nbsp;c(13,13,20,20),#&nbsp;inner&nbsp;2&nbsp;values&nbsp;dictate&nbsp;height&nbsp;of&nbsp;horizontal&nbsp;line.&nbsp;Outer:&nbsp;vertical&nbsp;edge&nbsp;lines. &nbsp;&nbsp;x8&nbsp;=&nbsp;c(.8,.8,1.26,1.26),&nbsp;#&nbsp;1st&nbsp;2&nbsp;values&nbsp;dictate&nbsp;starting&nbsp;point&nbsp;of&nbsp;line.&nbsp;2nd&nbsp;2&nbsp;dictate&nbsp;width.&nbsp;Each&nbsp;whole&nbsp;=&nbsp;one&nbsp;background&nbsp;grid &nbsp;&nbsp;y8&nbsp;=&nbsp;c(0,0,20,20),#&nbsp;inner&nbsp;2&nbsp;values&nbsp;dictate&nbsp;height&nbsp;of&nbsp;horizontal&nbsp;line.&nbsp;Outer:&nbsp;vertical&nbsp;edge&nbsp;lines. &nbsp;&nbsp;#Variable&nbsp;=&nbsp;"Diagonal&nbsp;Pattern", &nbsp;&nbsp;Fill&nbsp;=&nbsp;"Diagonal&nbsp;Pattern" &nbsp;&nbsp;)在那里,我将geom_path添加到上面的ggart中,每个路径调用不同的坐标,并在所需的条形图上绘制线:+geom_path(data=Diag,&nbsp;aes(x=x,&nbsp;y=y),colour&nbsp;=&nbsp;"black")+&nbsp;&nbsp;#&nbsp;calls&nbsp;co-or&nbsp;for&nbsp;sig.&nbsp;line&nbsp;&&nbsp;draws &nbsp;&nbsp;geom_path(data=Diag,&nbsp;aes(x=x2,&nbsp;y=y2),colour&nbsp;=&nbsp;"black")+&nbsp;&nbsp;#&nbsp;calls&nbsp;co-or&nbsp;for&nbsp;sig.&nbsp;line&nbsp;&&nbsp;draws &nbsp;&nbsp;geom_path(data=Diag,&nbsp;aes(x=x3,&nbsp;y=y3),colour&nbsp;=&nbsp;"black")+ &nbsp;&nbsp;geom_path(data=Diag,&nbsp;aes(x=x4,&nbsp;y=y4),colour&nbsp;=&nbsp;"black")+ &nbsp;&nbsp;geom_path(data=Diag,&nbsp;aes(x=x5,&nbsp;y=y5),colour&nbsp;=&nbsp;"black")+ &nbsp;&nbsp;geom_path(data=Diag,&nbsp;aes(x=x6,&nbsp;y=y6),colour&nbsp;=&nbsp;"black")+ &nbsp;&nbsp;geom_path(data=Diag,&nbsp;aes(x=x7,&nbsp;y=y7),colour&nbsp;=&nbsp;"black")结果如下:这是有点草率,因为我没有投入太多的时间,使线条完美的角度和间隔,但这应该是一个概念的证明。显然,这些线可以向相反的方向倾斜,也有对角啮合的空间,就像水平和垂直啮合一样。我想这大概是我能提供的全部了。希望有人能找到它的用处。编辑3:著名的遗言。我想出了另一种模式选择。这一次使用geom_jitter.我再次在数据框架中添加了另一个变量:Example.Data[5,]&nbsp;<-&nbsp;c(100,&nbsp;'Bubble&nbsp;Pattern','Bubble&nbsp;Pattern'&nbsp;)我命令我希望每一个图案都呈现出来:Example.Data$Variable&nbsp;=&nbsp;Relevel(Example.Data$Variable,&nbsp;ref&nbsp;=&nbsp;c("Diagonal&nbsp;Pattern",&nbsp;"Bubble&nbsp;Pattern","Horizontal&nbsp;Pattern","Mesh&nbsp;Pattern","Vertical&nbsp;Pattern"))接下来,我创建了一个列,以包含与x轴上的预定目标栏相关联的数字:Example.Data$Bubbles&nbsp;<-&nbsp;2后面是列,以包含“气泡”y轴上的位置:Example.Data$Points&nbsp;<-&nbsp;c(5,&nbsp;10,&nbsp;15,&nbsp;20,&nbsp;25)Example.Data$Points2&nbsp;<-&nbsp;c(30,&nbsp;35,&nbsp;40,&nbsp;45,&nbsp;50)Example.Data$Points3&nbsp;<-&nbsp;c(55,&nbsp;60,&nbsp;65,&nbsp;70,&nbsp;75)Example.Data$Points4&nbsp;<-&nbsp;c(80,&nbsp;85,&nbsp;90,&nbsp;95,&nbsp;7)Example.Data$Points5&nbsp;<-&nbsp;c(14,&nbsp;21,&nbsp;28,&nbsp;35,&nbsp;42)Example.Data$Points6&nbsp;<-&nbsp;c(49,&nbsp;56,&nbsp;63,&nbsp;71,&nbsp;78)Example.Data$Points7&nbsp;<-&nbsp;c(84,&nbsp;91,&nbsp;98,&nbsp;6,&nbsp;12)最后我加入了geom_jitter使用新列进行定位,并重复使用“点”来改变“气泡”的大小:+geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points2,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points2,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points3,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points4,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points2,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points2,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points3,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points4,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points2,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points5,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points5,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points6,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points6,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points7,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points7,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points2,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points2,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points3,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points4,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points2,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points2,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points3,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points4,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points2,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points5,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points5,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points6,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points6,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points7,&nbsp;size=Points),&nbsp;alpha=.5)+ &nbsp;&nbsp;geom_jitter(data=Example.Data,aes(x=Bubbles,&nbsp;y=Points7,&nbsp;size=Points),&nbsp;alpha=.5)每次运行该情节时,抖动位置的“泡泡”都不同,但下面是我得到的更好的输出之一:有时,“泡沫”会在边界之外抖动。如果发生这种情况,请重新运行或简单地在更大的维度中导出。在y轴上的每一个增量上都可以画出更多的气泡,如果你愿意的话,这将填补更多的空白。这构成了多达7种模式(如果你包括相反的斜线和对角线的两种),可以被黑在gg图中。如果有人能想到一些,请随时提出更多建议。编辑4:我一直在开发一个包装器函数来自动化gplot 2中的孵化/模式。我将在扩展函数之后发布一个链接,以允许facet_Grid图等中的模式。下面是一个输出,其中包含一个简单的条形图的函数输入,例如:一旦我准备好了要共享的函数,我将添加最后一个编辑。编辑5:这里有一个链接对于我编写的函数EggHatch,将模式添加到geom_bar绘图中的过程更容易一些。
打开App,查看更多内容
随时随地看视频慕课网APP