r语言中进行数据可视化

R programming was developed in 1993 for making graphs and producing statistical results. There are many libraries in R language that can be used for making graphs and producing statistical data.

R编程于1993年开发,用于制作图形和产生统计结果。 R语言中有许多库可用于制作图形和生成统计数据。

There are many steps that have to be taken into consideration for doing data analysis through this language. These steps are:

通过这种语言进行数据分析时,必须考虑许多步骤。 这些步骤是:

  • Programming
    程式设计
  • Transforming
    转型
  • Discovering
    发现
  • Modeling
    造型
  • Communicating
    沟通交流

R programming is being used in many industries like academics, healthcare, government, insurance, retail, media, manufacturing, etc.

R编程已在许多行业中使用,例如学术界,医疗保健,政府,保险,零售,媒体,制造业等。

This data analysis can be done through programming in R language which comes with a number of packages having many inbuilt functions and this is the reason that developers do not have to program much. They just need to use those functions and carry out the analysis.

可以通过R语言编程来完成此数据分析,R语言带有许多具有许多内置功能的程序包,这是开发人员不必进行太多编程的原因。 他们只需要使用这些功能并进行分析即可。

为什么要使用R编程? (Why R Programming?)

R Programming can be used to create statistics and graphs. The language has become very popular and people who want to make their career in this language can undergo R certification online through various institute who provide in-depth knowledge of R.

R编程可用于创建统计数据和图形。 该语言已变得非常流行,并且想要使用该语言进行职业的人们可以通过提供R深入知识的各种机构在线获得R认证 。

R certification when seen today can prove to be very useful for students and they can plan a good career after the certification which certainly gives an individual an upper edge over others.

今天看到的R认证可能对学生非常有用,并且他们可以在认证之后计划一个良好的职业,这肯定会使个人在其他方面拥有上风。

R中的数据可视化 (Data Visualization in R)

Many types of data visualizations can be created through the language and these are:

通过该语言可以创建多种类型的数据可视化,它们是:

  • Histogram
    直方图
  • Bar / Line Chart
    条形图/折线图
  • Box plot
    箱形图
  • Scatter plot
    散点图
  • Heat Map
    热图
  • Mosaic Map
    镶嵌图
  • Map Visualization
    地图可视化
  • 3D Graphs
    3D图形
  • Correlogram
    相关图

These will be discussed one by one.

这些将一一讨论。

直方图 (Histogram)

A histogram can be created by using histdata package that has many small data sets to create the histogram. A histogram can be used to break data into bins and show their frequency. Here is the code in which histogram is created. Here is the code of creating a simple histogram.

直方图可以通过使用具有许多小的数据集来创建直方图的histdata包来创建。 直方图可用于将数据分解为bin,并显示其频率。 这是创建直方图的代码。 这是创建简单直方图的代码。

hist(Temperature,
main="Maximum daily temperature ",
xlab="Temperature in degrees Fahrenheit",
xlim=c(50,100),
col="darkmagenta",
freq=FALSE
)

Image Source

图片来源

While creating a histogram a developer can see that number of colors specified is more than the number of breaks. The colors are repeated if the number of colors is more.

在创建直方图时,开发人员可以看到指定的颜色数量大于中断的数量。 如果颜色数量更多,则重复颜色。

折线图 (Line Chart)

A line chart shows an increase in the data for a given time period. Line charts are created to compare the changes between two organizations or between weather of two places or other comparisons. Line charts are also created to analyze the trends over a particular period.

折线图显示给定时间段内数据的增加。 创建折线图是为了比较两个组织之间或两个地方的天气之间的变化或进行其他比较。 还创建折线图以分析特定时期内的趋势。

x <- c(1:5); y <- x
par(pch=22, col="red")
par(mfrow=c(2,4))
opts = c("p","l","o","b","c","s","S","h")
for(i in 1:length(opts)){heading = paste("type=",opts[i])plot(x, y, type="n", main=heading)lines(x, y, type=opts[i])
}

Image Source

图片来源

条形图 (Bar Chart)

Bar chart is also created for comparing profits or weather report or other comparisons. The chart is displayed in the form of bars. Here is the code of creating a vertical bar chart.

还创建了条形图,用于比较利润或天气预报或其他比较。 图表以条形形式显示。 这是创建垂直条形图的代码。

counts <- table(mtbikes$gear)
barplot(counts, main="Bike Distribution",xlab="Number of Gears")

Image Source

图片来源

Here is an example of creating a horizontal bar chart.

这是创建水平条形图的示例。

counts <- table(mtbikes$gear)
barplot(counts, main="Bike Distribution", horiz=TRUE,names.arg=c("3 Gears", "4 Gears", "5 Gears"))

箱形图 (Box Plot)

It is created either for a single variable or a group of variables. The syntax of creating a box plot is as follows

它是为单个变量或一组变量创建的。 创建箱形图的语法如下

boxplot(x,data=)

Here x is the formula and data= is the frame which provides the data. Here is an example of creating a box plot.

这里x是公式,data =是提供数据的框架。 这是创建箱形图的示例。

boxplot(mpg~cyl,data=mtbikes, Bike Milage Data",xlab="Number of Cylinders", ylab="Miles Per Gallon")

Image Source

图片来源

散点图 (Scatter Plot)

Scatter plot can be created in many ways. The basic formula for creating the scatter plot is

散点图可以通过多种方式创建。 创建散点图的基本公式是

plot(x, y)

Here is an example of creating a scatter plot.

这是创建散点图的示例。

attach(mtbikes)
plot(wt, mpg, main="Scatterplot Example",xlab="Bike Weight ", ylab="Miles Per Gallon ", pch=19)

热图 (Heat Map)

A heat map is displayed in the form of a table in which colors are displayed in place of numbers. All the columns can have either same or different colors. The dark color denotes highs while the light colors denote lows. Here is an example of creating a heat map.

热图以表格的形式显示,其中以颜色代替数字来显示颜色。 所有列可以具有相同或不同的颜色。 深色表示高,而浅色表示低。 这是创建热图的示例。

> heatmap(as.matrix(mtcars))

镶嵌图 (Mosaic Map)

Mosaic Map can be created by using VCD library which has an ample amount of functions to create the map. The syntax for creating a mosaic map is as follows:

可以使用VCD库创建马赛克地图,该库具有创建地图的大量功能。 创建镶嵌图的语法如下:

mosaic(x, condvar=, data=)

Here x is the formula and codevar is an optional variable in which conditions can be defined. The example below shows the making of a mosaic map

这里x是公式,而codevar是可以在其中定义条件的可选变量。 以下示例显示了镶嵌图的制作

library(vcd)
mosaic(HairEyeColor, shade=TRUE, legend=TRUE)

3D图形 (3D Graphs)

R programming can be used to create 3D graphs which are very impressive. The R commander package is used to create these graphs. In order to create the 3D graph R commander package has to be installed and then 3D plot option should be used in the graph.

R编程可用于创建令人印象深刻的3D图形。 R命令程序包用于创建这些图。 为了创建3D图形,必须安装R命令程序包,然后在图形中使用3D绘图选项。

Here is the code for creating the graph:

这是用于创建图形的代码:

>data(iris, package="datasets")
>scatter3d(Petal.Width~Petal.Length+Sepal.Length|Species, data=iris, fit="linear"
>residuals=TRUE, parallel=FALSE, bg="black", axis.scales=TRUE, grid=TRUE, ellipsoid=FALSE)

Lattice package can also be used to create 3D graphs.

莱迪思软件包还可用于创建3D图形。

Here is an example

这是一个例子

>attach(iris)
>cloud(Sepal.Length~Sepal.Width*Petal.Length|Species, main="3D Scatterplot by Species")
>xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)

相关图 (Correlogram)

Correlogram helps the users to view the data in the form of matrices. The syntax for creating a correlogram is given below.

关联图可帮助用户以矩阵形式查看数据。 下面给出了创建相关图的语法。

corrgram(x, order = , panel=, lower.panel=, upper.panel=, text.panel=, diag.panel=)

Here

这里

Order=TRUE will set the variables in proper order in relation to the correlation matrix.

Order = TRUE将按照相关矩阵的正确顺序设置变量。

Panel= refers to diagonal panels in which developers can use lower= and upper=. These options can be chosen below and above the diagonal. Text.panel and diag.panel are the references to main diagonal.

Panel =是指对角线面板,开发人员可以在其中使用lower =和upper =。 可以在对角线的下方和上方选择这些选项。 Text.panel和diag.panel是对角线的引用。

Here is an example of creating a correlogram.

这是创建相关图的示例。

library(corrgram)
corrgram(mtbikes, order=TRUE, lower.panel=panel.shade,upper.panel=panel.pie, text.panel=panel.txt,main="Bike Milage Data in PC2/PC1 Order")

地图可视化 (Map Visualization)

This is the latest thing that has been put into the R programming. R can provide the map visualization through JavaScript libraries. The leaflet is open source through which JavaScript libraries can be used for creating interactive maps. In order to use the library, it should be installed.

这是R编程中最新的东西。 R可以通过JavaScript库提供地图可视化。 该传单是开放源代码,通过它可以将JavaScript库用于创建交互式地图。 为了使用该库,应该安装它。

library(magrittr)
library(leaflet)
m <- leaflet() %>%
addTiles() %>%
addMarkers(lng=77.2310, lat=28.6560, popup="The delicious food of India")
m

己宾 (Hexbin)

Hexbin is a package, which helps to create multiple points This package can be used to create a bivariate histogram. Here is the code for the same.

Hexbin是一个程序包,可帮助创建多个点。此程序包可用于创建双变量直方图。 这是相同的代码。

>library(hexbin)
>a=hexbin(diamonds$price,diamonds$carat,xbins=40)
>library(RColorBrewer)
>plot(a)

最终裁决 (Final Verdict)

It can be said that various kinds of graphs can be made from R language by writing few lines of code and embedding packages and functions, which have already been coded.

可以说,通过编写很少的代码行并嵌入已经编码的包和函数,可以用R语言制成各种图形。

These charts can be used on the web as well as desktop applications and can help you for data visualization in R in a specific way.

这些图表可以在Web以及桌面应用程序上使用,并且可以帮助您以特定方式在R中进行数据可视化。

翻译自: https://www.thecrazyprogrammer.com/2018/12/data-visualization-in-r.html

r语言中进行数据可视化

r语言中进行数据可视化_R中的数据可视化相关推荐

  1. r语言写内曼最优分配_R中最优化函数optim

    最优化函数optim 目标函数: $$f(x_1,x_2)=(1-x_1)^2+100(x_2-x_1^2)^2$$ 该函数全局最小值在($x_1=1,x_2=1$)时取到. 下面这种写法是因为有多个 ...

  2. R语言survival包的survfit函数拟合生存曲线数据、survminer包的ggsurvplot函数可视化生存曲线、使用pval参数自定义指定生存曲线中可视化的p值、为p值添加文本说明内容

    R语言survival包的survfit函数拟合生存曲线数据.survminer包的ggsurvplot函数可视化生存曲线.使用pval参数自定义指定生存曲线中可视化的p值.为p值添加文本说明内容 目 ...

  3. R语言使用na.omit函数删除矩阵matrix数据中的缺失值(NA值)

    R语言使用na.omit函数删除矩阵matrix数据中的缺失值(NA值) 目录 R语言使用na.omit函数删除矩阵matrix数据中的缺失值(NA值) R 语言特点 R语言使用na.omit函数删除 ...

  4. R语言使用多个数据类型不同的向量数据创建一个dataframe数据对象、使用列名称(column name)访问dataframe中的指定数据列的数据

    R语言使用多个数据类型不同的向量数据创建一个dataframe数据对象.使用列名称(column name)访问dataframe中的指定数据列的数据 目录 R语言使用多个数据类型不同的向量数据创建一 ...

  5. R语言使用edit函数在Rsudio中生成数据编辑器(在windows中生成编辑器)、在编辑器中输出需要的数据生成最终的dataframe

    R语言使用edit函数在Rsudio中生成数据编辑器(在windows中生成编辑器).在编辑器中输出需要的数据生成最终的dataframe 目录

  6. R语言入门第四集 实验三:数据可视化

    R语言入门第四集 实验三:数据可视化 一.资源 [R语言]R语言数据可视化--东北大学大数据班R实训第三次作业 在r中rowsums_R语言初级教程(15): 矩阵(下篇) R语言环境变量的设置 环境 ...

  7. R语言结构方程模型在生态学领域中的应用

    结构方程模型(Sructural Equation Model)是一种建立.估计和检验研究系统中多变量间因果关系的模型方法,它可以替代多元回归.因子分析.协方差分析等方法,利用图形化模型方式清晰展示研 ...

  8. R语言层次聚类(hierarchical clustering):数据缩放、PCA聚类结果可视化、fpc包的clusterboot函数通过bootstrap重采样的方法评估hclust层次聚类的稳定性

    R语言层次聚类(hierarchical clustering):数据缩放.PCA聚类结果可视化.fpc包的clusterboot函数通过bootstrap重采样的方法评估hclust层次聚类的稳定性 ...

  9. R语言使用cor函数计算dataframe中多个数值数据列之间的相关性系数、计算spearman非参数的等级相关性系数

    R语言使用cor函数计算dataframe中多个数值数据列之间的相关性系数.计算spearman非参数的等级相关性系数 目录 R语言使用cor函数计算dataframe中多个数值数据列之间的相关性系数 ...

  10. R语言survival包的survfit函数拟合生存曲线数据、survminer包的ggsurvplot函数可视化生存曲线、size参数指定曲线粗细、palette参数自定义生存曲线的颜色

    R语言survival包的survfit函数拟合生存曲线数据.survminer包的ggsurvplot函数可视化生存曲线.size参数指定曲线粗细.palette参数自定义生存曲线的颜色 目录

最新文章

  1. careercup-高等难度 18.9
  2. blog搬家通知---------------------------------------
  3. MySQL数据库服务器的架设
  4. 机器学习入门需要多久
  5. 2020年余丙森概率统计强化笔记-第五章 大数定律和中心极限定理 第六章 数理统计
  6. 自动配置IE代理脚本
  7. 飞桨PaddlePaddle送算力 | 每日登录即送12小时,连续5天还有加送!
  8. emwin之在中断服务程序中创建窗口的结果
  9. win7的python3.5安装numpy包
  10. Python中字符串操作函数string.split('str1')和string.join(ls)
  11. python爬虫安装错误与解决方式
  12. java猜数字代码,我写的猜数字游戏的java代码!
  13. php7 memcached sasl,Mac安装memcached扩展支持sasl
  14. 2021春节档票房超78亿元收官 总观影人次达1.6亿
  15. c#加mysql简单系统_visual studio2019连接MYSQL数据库详细教程(C#代码)
  16. 2021 牛津大学:Recent Advances in Reinforcement Learning in Finance
  17. win10环境下创建环境变量
  18. 数据库与MPP数仓(二十三):postgreSQL集群与高级特性
  19. 阴阳师服务器紧急维护,2月24日阴阳师服务器更新维护内容公告
  20. 5G NR 频率计算

热门文章

  1. android是不是百合手机号码,百合定位(百合定位电话手表)V1.0.16 手机版
  2. 【统计学】详解 A/B 测试
  3. Testin云测试:联想K900热卖 完美兼容10000款主流App
  4. 设计数据库中常见的规范
  5. 【pytest】(二) pytest与unittest的比较
  6. 知行学徒人脸识别伪造
  7. CSS——CSS浮动与清除浮动
  8. JS 判断浏览器版本
  9. 自学之路——七年之痒 ----------BY小生我怕怕前辈
  10. 人生之路 — 学会寡言