数据可视化——R语言使用ggplot2工具包绘制分面的曲线图
概述:R语言使用ggplot2工具包绘制分面的曲线图,即依据数据的不同属性进行分面显示,并详细设置了不同绘图参数,使得绘制的图形更美观。
使用工具:R语言中的ggplot2工具包, RcolorBrewer颜色工具包
RcolorBrewer包在我之前的博客有介绍,请参考:数据可视化——R语言使用ggplot2工具包绘制精美的条形图(https://blog.youkuaiyun.com/zhouhucheng00/article/details/85801297)
下面展示一个我的示例,主要是对各种绘图参数进行了仔细设置,使得图形更美观。示例中的数据为模拟生成的。模拟数据包括两个组别group1和group2,每个组别5个属性(Attribute_1到 Attribute_5),每个组别的每个属性都有相应的横(X_value)纵(Y_value)坐标的值。
代码如下:
rm(list=ls()) #清除工作区
library(ggplot2)
library(RColorBrewer)
#生成模型数据
Group <- c(rep("group1",30),rep("group2",30))
Attribute <- c(rep("Attribute_1",10),rep("Attribute_2",10),rep("Attribute_3",10),
rep("Attribute_1",10),rep("Attribute_2",10),rep("Attribute_3",10))
X_value <-