R可视化系列——散点图美化

xiaoxiao2021-02-28  20

library(RColorBrewer) library(ggplot2) q<-ggplot(diamonds,aes(carat,price))+scale_color_manual(values=brewer.pal(9,"YlOrRd")[3:7]) q<-q+guides(colour=guide_legend(title=NULL)) q+geom_point(aes(colour=cut)) +theme(panel.grid.minor=element_line(colour='#FFcccc',size=1), ###更改副网格线的颜色以及线条粗细### axis.title=element_text(color='red',face = "bold",size=15), ###更改坐标名称的颜色,字体,字号### panel.background = element_rect(fill='#FFF0F5'), ###更改背景填充颜色### axis.ticks= element_blank(), ###删除所有坐标轴刻度### axis.text=element_text(size=12,colour='red',face='bold' ###坐标轴刻度线颜色,字体,字号### panel.grid=element_blank(), ###绘图区网格线删除### panel.border=element_rect(color="#FF6666",fill='transparent',linetype ='solid',size=1.5)) ###绘图区外框颜色,外框线型以及粗细,填充透明色!)###

                                              

从gcookbook包中调用diamonds数据,应用carat和price数据做出基本散点图,在此基础上进行美化设计。 在可视化的过程中,主要利用了 RColorBrewer包进行色彩的调用(参考 https://www.cnblogs.com/homewch/archive/2016/07/25/5704153.html网址,有详细的调用说明) 今天也学习了theme函数中的相关参数设置(参考http://blog.sina.com.cn/s/blog_69ffa1f90101sigd.html)。 利用theme进行主题设置时,有四个重要函数的使用方式需要掌握:

element_blank()element_rect(fill,colour,size,linetype,color,inheret.blank)element_line(coloue,size,linetype,lineend,color,arrow,inherit.blank)element_text(family,face,null,colour,size,hjust,vjust,angle,lineheight,color,margin,debug,inherit_blank) 在使用过程中,对应以上四种类型进行修改即可 参数设置内容继承自line所有线属性 rect所有矩形区域属性 text所有文本相关属性 title所有标题属性 axis.title坐标轴标题textaxis.title.xx轴属性axis.titleaxis.title.yy轴属性axis.titleaxis.text坐标轴刻度标签属性textaxis.text.x属性和继承和前面类似,不再重复 axis.text.y  axis.ticks坐标轴刻度线lineaxis.ticks.x  axis.ticks.y  axis.ticks.length刻度线长度 axis.ticks.margin刻度线和刻度标签之间的间距 axis.line坐标轴线lineaxis.line.x  axis.line.y  legend.background图例背景rectlegend.margin图例边界 legend.key图例符号 legend.key.size图例符号大小 legend.key.height图例符号高度 legend.key.width图例符号宽度 legend.text图例文字标签 legend.text.align图例文字标签对齐方式0为左齐,1为右齐legend.title图例标题textlegend.title.align图例标题对齐方式 legend.position图例位置left, right, bottom, top, 两数字向量legend.direction图例排列方向"horizontal" or "vertical"legend.justification居中方式center或两数字向量legend.box多图例的排列方式"horizontal" or "vertical"legend.box.just多图例居中方式 panel.background绘图区背景rectpanel.border绘图区边框rectpanel.margin分面绘图区之间的边距 panel.grid绘图区网格线linepanel.grid.major主网格线 panel.grid.minor次网格线 panel.grid.major.x  panel.grid.major.y  panel.grid.minor.x  panel.grid.minor.y  plot.background整个图形的背景 plot.title图形标题 plot.margin图形边距top, right, bottom, leftstrip.background分面标签背景rectstrip.text分面标签文本textstrip.text.x  strip.text.y  

转载请注明原文地址: https://www.6miu.com/read-2624781.html

最新回复(0)