## 用数据说话，R语言有哪七种可视化应用？

| |
[ 所属分类 网络安全 | 发布者 店小二05 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

1、 比较类图表

2、 组成类图表

3、 分布类图表

4、 关系类图表

1． 散点图

2． 直方图

3． 柱状图和条形图

4． 箱线图

5． 面积图

6． 热点图

7． 相关图

1、 散点图

library(ggplot2) // ggplot2 是R中的一个函数库

ggplot(train, aes(Item_Visibility, Item_MRP)) + geom_point() + scale_x_continuous("Item

Visibility", breaks = seq(0,0.35,0.05))+ scale_y_continuous("Item MRP", breaks = seq(0,270,by =

30))+ theme_bw()

R代码中增加了分组：

ggplot(train, aes(Item_Visibility, Item_MRP)) + geom_point(aes(color = Item_Type)) +

scale_x_continuous("Item Visibility", breaks = seq(0,0.35,0.05))+

scale_y_continuous("Item MRP", breaks = seq(0,270,by = 30))+

theme_bw() + labs(title="Scatterplot")

ggplot(train, aes(Item_Visibility, Item_MRP)) + geom_point(aes(color = Item_Type)) +

scale_x_continuous("Item Visibility", breaks = seq(0,0.35,0.05))+

scale_y_continuous("Item MRP", breaks = seq(0,270,by = 30))+

theme_bw() + labs(title="Scatterplot") + facet_wrap( ~ Item_Type)

2、 直方图

ggplot(train, aes(Item_MRP)) + geom_histogram(binwidth = 2)+

scale_x_continuous("Item MRP", breaks = seq(0,270,by = 30))+

scale_y_continuous("Count", breaks = seq(0,200,by = 20))+

labs(title = "Histogram")

3、 柱状图和条形图

ggplot(train, aes(Outlet_Establishment_Year)) + geom_bar(fill = "red")+theme_bw()+

scale_x_continuous("Establishment Year", breaks = seq(1985,2010)) +

scale_y_continuous("Count", breaks = seq(0,1500,150)) +

coord_flip()+ labs(title = "Bar Chart") + theme_gray()

ggplot(train, aes(Item_Type, Item_Weight)) + geom_bar(stat = "identity", fill = "darkblue") +

scale_x_discrete("Outlet Type")+ scale_y_continuous("Item Weight", breaks = seq(0,15000, by =

500))+ theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) + labs(title = "Bar Chart")

ggplot(train, aes(Outlet_Location_Type, fill = Outlet_Type)) + geom_bar()+

labs(title = "Stacked Bar Chart", x = "Outlet Location Type", y = "Count of Outlets")

4、 箱线图

ggplot(train, aes(Outlet_Identifier, Item_Outlet_Sales)) + geom_boxplot(fill = "red")+

scale_y_continuous("Item Outlet Sales", breaks= seq(0,15000, by=500))+

labs(title = "Box Plot", x = "Outlet Identifier")

5、 面积图

ggplot(train, aes(Item_Outlet_Sales)) + geom_area(stat = "bin", bins = 30, fill = "steelblue") +

scale_x_continuous(breaks = seq(0,11000,1000))+

labs(title = "Area Chart", x = "Item Outlet Sales", y = "Count")

6 、 热点图

ggplot(train, aes(Outlet_Identifier, Item_Type))+

geom_raster(aes(fill = Item_MRP))+

labs(title ="Heat Map", x = "Outlet Identifier", y = "Item Type")+

scale_fill_continuous(name = "Item MRP")

7、 关系图

install.packages("corrgram")

library(corrgram)

main="Correlogram")

Via Tatvic

tags: Item,ggplot,scale,MRP,Outlet,continuous,geom,seq,breaks,aes,图表,train,Type,变量,可视化

1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责；
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性，不作出任何保证或承若；
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。