Intermediate Language R drawing: D scattergram

Chapter, we focus on the method for drawing shows inter-relationship and bivariate relationship multivariate
This section describes: a three-dimensional scattergram, a three-dimensional scattergram rotation, Bubble
dimensional scattergram
using the function scatterplot3d () to draw a three-dimensional Scatter
example

install.packages("scatterplot3d")
library(scatterplot3d)
attach(mtcars)
scatterplot3d(wt,disp,mpg,main="Basic 3D Scatter Plot")

Here Insert Picture Description

scatterplot3d () function provides a number of options provided comprising graphic symbols, axis, colors, lines, grid lines, and the angle of projection display functions.
Code Example:

library(scatterplot3d)
attach(mtcars)
scatterplot3d(wt,disp,mpg,
              pch=16,
              #点的颜色将随着y坐标的不同而不同
              highlight.3d = TRUE,
              #添加连接点与水平面的垂直线
              type="h",
              main="Basic 3D Scatter Plot")

Here Insert Picture Description

Add a surface regression
code sample

library(scatterplot3d)
attach(mtcars)
s3d <- scatterplot3d(wt,disp,mpg,
              pch=16,
              #点的颜色将随着y坐标的不同而不同
              highlight.3d = TRUE,
              #添加连接点与水平面的垂直线
              type="h",
              main="Basic 3D Scatter Plot")
fit <- lm(mpg~wt+disp)
#图形利用多元回归方程,对通过车重和排量预测每加仑英里数进行可视化处理,平面代表预测值。点表示实际值
s3d$plane3d(fit)

Here Insert Picture Description
11.1.4 rotating three-dimensional scatter plot
R provides some rotation of graphics features that let you draw can be observed from multiple angles data points
rgl package plot3d () function to create a three-dimensional scatter plot interaction. Graphics can be rotated with the mouse. Function format
plot3d (x, y, z)
where x, y, z are numerical vector representing respective points.
The sample code

library(rgl)
attach(mtcars)
#参数size可以控制点的大小
plot3d(wt,disp,mpg,col="red",size=5)

Here Insert Picture Description
scatter3d car pack () has a similar function
scatter3d () function may include various regression curved surface, such as a linear, quadratic, smooth and additional types. Linear plane pattern added by default.

library(car)
attach(mtcars)
scatter3d(wt,disp,mpg)

Here Insert Picture Description
11.1.5 bubble chart
showing the relationship between the three quantitative variables, can create a two-dimensional scattergram, and then the size of the dots to represent the value of the third variable. This is the bubble chart
symbols () function creates a bubble chart
symbols () function can be plotted on a circle in FIG specified (x, y) coordinates, FIG square, star chart, FIG thermometer, boxplots
draws circles FIG Code
symbols (x, y, circle = radius )
where x, y, is the need to set rADIUS vectors, each represents a radius x, y coordinates of the circle, and
if you want to use to represent the area instead of a radius of a third variable, use the formula
symbols (X, Y, Circle = sqrt (Z / PI))
Z is a third variable to draw
sample code

attach(mtcars)
#以面积来表示向量disp的大小
r <- sqrt(disp/pi)
#inches是比例因子,控制着圆圈大小,fg指定圆圈边界的颜色,bg指定圆圈的颜色
symbols(wt,mpg,circle=r,inches = 0.3,
        fg="white",bg="lightblue",
        main="Bubble Plot with point size proportional to displacement",
        ylab="Mile Per Gallon",
        xlab="Weight of Car (lbs/1000)")
text(wt,mpg,labels=row.names(mtcars),cex = 0.5)
detach(mtcars)

Here Insert Picture Description
FIG other graphical bubble

attach(mtcars)
#以面积来表示向量disp的大小
r <- sqrt(disp)
#inches是比例因子,控制着圆圈大小,fg指定圆圈边界的颜色,bg指定圆圈的颜色
symbols(wt,mpg,circle =r,inches = 0.3,
        fg="white",bg= 1:11,
        main="Bubble Plot with point size proportional to displacement",
        ylab="Mile Per Gallon",
        xlab="Weight of Car (lbs/1000)")
text(wt,mpg,labels=row.names(mtcars),cex = 0.5)

Here Insert Picture Description

Summary:
drawing a three-dimensional scatter plot may be used scatterplot3d package Scatterplot () function
to draw a three-dimensional scattergram can be used rotating rgl package Plot3D () function or car package scatter3d () function is
a bubble diagram for showing three the relationship between two quantitative variables, you can create a two-dimensional scatter plot, then the size of the dots to represent the value of a third variable.
Symbols may be used () function to create a bubble chart

Published 39 original articles · won praise 11 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_42712867/article/details/100129746