1.条形图:barplot()
添加标题:main = ’ ’
添加坐标轴标题:xlab = ’ ’ , ylab = ’ ’
region2 <- table(example1
R
e
g
i
o
n
2
)
r
l
a
b
e
l
s
<
−
c
(
′
N
o
r
t
h
′
,
′
S
o
u
t
h
′
,
′
F
o
r
e
i
g
n
′
,
′
E
a
s
t
′
,
′
W
e
s
t
′
)
b
a
r
p
l
o
t
(
r
e
g
i
o
n
2
)
b
a
r
p
l
o
t
(
r
e
g
i
o
n
2
,
n
a
m
e
s
.
a
r
g
=
r
l
a
b
e
l
s
)
b
a
r
p
l
o
t
(
r
e
g
i
o
n
2
,
n
a
m
e
s
.
a
r
g
=
r
l
a
b
e
l
s
,
m
a
i
n
=
"
B
a
r
C
h
a
r
t
f
o
r
R
e
g
i
o
n
"
)
b
a
r
p
l
o
t
(
r
e
g
i
o
n
2
,
n
a
m
e
s
.
a
r
g
=
r
l
a
b
e
l
s
,
m
a
i
n
=
"
B
a
r
C
h
a
r
t
f
o
r
R
e
g
i
o
n
"
,
x
l
a
b
=
"
R
e
g
i
o
n
"
,
y
l
a
b
=
"
C
o
u
n
t
"
)
2.
饼
图
:
p
i
e
(
)
p
i
e
(
r
e
g
i
o
n
2
)
p
i
e
(
r
e
g
i
o
n
2
,
m
a
i
n
=
′
P
i
e
C
h
a
r
t
f
o
r
R
e
g
i
o
n
′
,
l
a
b
e
l
s
=
r
l
a
b
e
l
s
)
3.
直
方
图
:
h
i
s
t
(
)
h
i
s
t
(
e
x
a
m
p
l
e
1
Region2) rlabels <- c('North', 'South', 'Foreign', 'East', 'West') barplot(region2) barplot(region2, names.arg = rlabels) barplot(region2, names.arg = rlabels, main = "Bar Chart for Region") barplot(region2, names.arg = rlabels, main = "Bar Chart for Region", xlab = "Region", ylab = "Count") 2.饼图:pie() pie(region2) pie(region2, main = 'Pie Chart for Region', labels = rlabels) 3.直方图:hist() hist(example1
Region2)rlabels<−c(′North′,′South′,′Foreign′,′East′,′West′)barplot(region2)barplot(region2,names.arg=rlabels)barplot(region2,names.arg=rlabels,main="BarChartforRegion")barplot(region2,names.arg=rlabels,main="BarChartforRegion",xlab="Region",ylab="Count")2.饼图:pie()pie(region2)pie(region2,main=′PieChartforRegion′,labels=rlabels)3.直方图:hist()hist(example1Price)
hist(example1
P
r
i
c
e
,
b
r
e
a
k
s
=
1
)
h
i
s
t
(
e
x
a
m
p
l
e
1
Price, breaks = 1) hist(example1
Price,breaks=1)hist(example1Price, breaks = c(1.3, 1.9, 2.5, 3.1, 3.7, 4.3))
4.箱线图:boxplot()
添加参考线:abline()
boxplot(example1
P
r
i
c
e
)
a
b
l
i
n
e
(
h
=
3
,
c
o
l
=
′
r
e
d
′
)
b
o
x
p
l
o
t
(
e
x
a
m
p
l
e
1
Price) abline(h = 3, col = 'red') boxplot(example1
Price)abline(h=3,col=′red′)boxplot(example1Price, horizontal = TRUE)
abline(v = 2, col = ‘blue’)
boxplot(example1
P
r
i
c
e
e
x
a
m
p
l
e
1
Price~example1
Price example1Region2, names = rlabels)
5.散点图:plot()
plot(example1
P
r
i
c
e
,
e
x
a
m
p
l
e
1
Price, example1
Price,example1Kilogram)
abline(a = 0, b = 0.5, col = ‘pink’)
text(x = 3.5, y = 2, labels = ‘y=0.5x’, col = ‘yellow’)
9.分区画图:par(mfrow = c(n,m))
par(mfrow = c(2,2))
barplot(region2, names.arg = rlabels, main = “Bar Chart for Region”, xlab = “Region”, ylab = “Count”)
pie(region2, main = ‘Pie Chart for Region’, labels = rlabels)
boxplot(example1
P
r
i
c
e
e
x
a
m
p
l
e
1
Price~example1
Price example1Region2, names = rlabels)
plot(example1
P
r
i
c
e
,
e
x
a
m
p
l
e
1
Price, example1
Price,example1Kilogram)
R中几种常用的绘图命令
最新推荐文章于 2023-07-27 15:44:03 发布