当前位置:
文档之家› 【原创】R语言数据可视化分析报告(附代码数据)
【原创】R语言数据可视化分析报告(附代码数据)
数据可视化分析报告
可见1此图形是一个传统的堆积条形图。 这个图形在内置于ggplot2库中的mpg数据集上工作。
library(ggplot2)
ggplot(mpg,aes(class,fill=trans))+geom_bar(position="stack")
echo=TRUE
可见2这个boxplot也是使用mpg数据集建立的。
Vis 3这个图形是用另一个数据集菱形建立的,也是内置在ggplot2包中的数据集。
library(ggthemes)
ggplot(diamonds)+geom_density(aes(price,fill=cut,color=cut),alpha=0.4,size=0.5)+labs(title='Diamond Price Density',x='Diamond Price (USD)',y='Density')+theme_economist()
ggplot(mpg)+geom_boxplot(aes(manufacturer,hwy))+theme_classic()+coord_flip()+labs(y="Highway Fuel Efficiency (mile/gallon)",x="Vehicle Manufacturer")eFra bibliotekho=TRUE
ggplot(iris,aes(x=iris$Sepal.Length,y=iris$Petal.Length,fill=Species,color=Species))+geom_point()+theme_minimal()+labs(x="Iris Sepal Length",y="Iris Petal Length",title="Relationship between Sepal and Petal Length")+geom_smooth(method=lm,se=FALSE)+theme(legend.position="bottom")
echo=TRUE
Vis 5 Finally, in this vis I extend on the last example, by plotting the same data but using an additional channel to communicate species level differences. Again I fit a linear model to the data but this time one for each species, and add additional theme and labeling modicitations.
echo=TRUE
echo=TRUE
另外,我正在使用ggplot2软件包来将线性模型拟合到框架内的所有数据上。
ggplot(iris,aes(Sepal.Length,Petal.Length))+geom_point()+geom_smooth(method=lm)+theme_minimal()+theme(panel.grid.major=element_line(size=1),panel.grid.minor=element_line(size=0.7))+labs(title='relationship between Petal and Sepal Length',x='Iris Sepal Length',y='Iris Petal Length')