geom_rect、geom_linerange、geom_segment、geom_ploygon。
这四个函数分别定义了ggplot2中的矩形图、垂直线图(线范围图)、线段图、几何多边形图。
这些函数都需要指定在坐标系统中的左边界、右边界、下边界、上边界。
分辨对应xmax,xmax,ymin,ymax等四个美学映射参数,当然单个矩形仍然可以执行分组颜色映射操作。
mydata <- data.frame(
Lebal = c("Point1","Point2","Point3","Point4","Point5"),
xstart = c(5.5,15.7,19.5,37.2,36.9),
xend = c(9.7,28.1,24.6,44.6,47.1),
ystart = c(9.6,23.1,2.3,33.2,9.2),
yend = c(16.1,36.2,11.7,38.5,15.3),
size = c(12,48,30,11.5,28),
class = c("A","A","A","C","C")
)
ggplot(mydata)+
geom_rect(aes(xmin = xstart,xmax = xend , ymin = ystart , ymax = yend , fill = class))
image.png
mydata <- data.frame(
Lebal = c("linerange1","linerange2","linerange3","linerange4","linerange5"),
xstart = c(3.5,7,12,16,20),
ymin = c(2.5,6.5,3,4.5,3.8),
ymax = c(7.5,9.5,9,13.5,4.2),
class = c("A","A","A","C","C")
)
ggplot(mydata) +
geom_linerange(aes(x = xstart, ymin = ymin , ymax = ymax , colour = class) , size = 1.5)
image.png
library(ggplot2)
mydata <- data.frame(
Lebal = c("Segment1","Segment2","Segment3","Segment4","Segment5"),
xstart = c(3.5,4.4,8.3,13.2,20),
ystart = c(5,2.7,4.6,2.2,4.7),
xend = c(7.5,8.7,21,25,23),
yend = c(7.9,4.2,7.2,3.8,4.4),
class = c("A","A","A","C","C")
)
ggplot(mydata) +
geom_segment(
aes(
x = xstart,
y = ystart,
xend = xend,
yend = yend,
colour = class
),
size = 1.5
)
ggplot(mydata) +
geom_segment(
aes(
x = xstart ,
y = ystart ,
xend = xend ,
yend = yend ,
colour = class
),
arrow = arrow(length = unit(0.5,"cm")),
size = 1.5
) +
scale_y_continuous(expand = c(0,0)) +
coord_polar(theta = 'x')
#
image.png
mydata <- data.frame(
long = c(15.4,17.2,19.7,15.9,7.4,8.9,8.5,10.4,11.3,9.7,4.8,3.7,22.4,25.6,27.8,25.1,16.7,15.9,29.9,38.7,43.2,40.2,35.6,29.4),
lat = c(38.1,36.2,33.1,24.6,29.0,33.6,12.1,11.7,8.9,6.1,5.7,9.1,8.4,7.6,5.7,3.9,4.3,5.9,32.6,31.8,27.6,22.3,24.5,29.6),
group= c(1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4),
order =c(1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6),
class = rep(c("A","c"),each = 12)
)
ggplot(mydata) +
geom_polygon(aes(x = long , y = lat , group = group , fill = class),colour = "white")
#按照X轴圆周化:
ggplot(mydata) +
geom_polygon(aes(x = long , y = lat , group = group , fill = class),colour = "white") +
coord_polar(theta = 'x') +
scale_x_continuous(expand = c(0,0))
#按照y轴圆周化:
ggplot(mydata) +
geom_polygon(aes(x = long , y = lat , group = group , fill = class),colour = "white") +
coord_polar(theta = 'y') +
scale_y_continuous(expand = c(0,0))
#分面:
ggplot(mydata) +
geom_polygon(aes(x = long , y = lat , group = group , fill = class),colour = "white") +
facet_grid(.~class)
网友评论