| 坐標(biāo)系 | 描述 |
| cartesian | 笛卡爾坐標(biāo)系 |
| equal | 同尺度笛卡爾坐標(biāo)系 |
| flip | 翻轉(zhuǎn)的笛卡爾坐標(biāo)系 |
| trans | 變換的的笛卡爾坐標(biāo)系 |
| polar | 極坐標(biāo) |
| map | 地圖投影 |
#準(zhǔn)備數(shù)據(jù)
library(ggplot2)
library(gridExtra)
o <- ggplot(data = gene_exp, aes(x = S1, y = S2)) +
geom_point() + labs(title = "origin")
# 同尺度笛卡爾坐標(biāo)系 x軸和y軸相同距離代表長(zhǎng)度一致
# o + coord_equal()
# coord_equal:保證x軸和y軸的1cm代表相同的數(shù)據(jù)范圍校翔”怪澹可以通過ratio調(diào)整比例,ratio=x/y
o_coord_equal <- o + coord_equal(ratio = 2) + labs(title = "o_coord_equal") +
scale_x_continuous(breaks= seq(0, 1600, 400))
grid.arrange(o, o_coord_equal, ncol = 2)
#翻轉(zhuǎn)的笛卡爾坐標(biāo)系,對(duì)于散點(diǎn)圖來說蛔翅,實(shí)際是x軸和y軸的交換赘来,
#有些圖形進(jìn)行翻轉(zhuǎn)(比如擬合曲線)狞悲,并不是單純的x軸和y軸的互換障本,主要用于:隨著y軸變化锡搜,觀察x軸變化的趨勢(shì)
#o + coord_flip()
o <- ggplot(data = gene_exp, aes(x = S1, y = S2)) +
geom_point() + labs(title = "origin") +
geom_smooth()
o_S2_S1 <- ggplot(data = gene_exp, aes(x = S2, y = S1)) +
geom_point() + labs(title = "origin_S2_S1") + geom_smooth()
o_coord_flip <- o + coord_flip() + labs(title = "o_coord_flip")
grid.arrange(o, o_S2_S1, o_coord_flip, ncol = 3)
#設(shè)置數(shù)據(jù)范圍:坐標(biāo)系與標(biāo)度的不同
#設(shè)置范圍
#coord_cartesian(xlim = c(0, 1000), ylim = c(0, 1000))
#標(biāo)度設(shè)置范圍:剔除范圍外數(shù)據(jù)员凝,再統(tǒng)計(jì)繪圖
#坐標(biāo)系設(shè)置范圍:仍使用所有數(shù)據(jù)統(tǒng)計(jì)變換 署驻,相當(dāng)于對(duì)圖形的局部放大
#導(dǎo)入包
library(ggplot2)
library(gridExtra)
#原始圖形
o <- ggplot(data = gene_exp, aes(x = S1, y = S2)) +
geom_point() + labs(title = "origin") +
geom_smooth()
#標(biāo)度,限制范圍
scale_trans <- o + xlim(1, 1000) + labs(title = "Scale_trans")
#坐標(biāo)系健霹,限制范圍
coord_trans <- o + coord_cartesian(xlim = c(0, 1000)) +
labs(title = "Coord_trans")
#比較
grid.arrange(o, scale_trans, coord_trans, ncol = 3)