ggplot2画图

tech2022-07-16  140

ggplot2 画图

基本要素 - Data - Mapping - Geometric - Scale - Statistics - Coordinate - Layer - Facet - Theme

查看ggplot2 里的 geom_函数

ls("package:ggplot2"

散点图 geom_point()

x+y

p <- ggplot(data = st.kilda, mapping = aes(x = BuildingArea, y = Price/1000)) p + geom_point()```

x + y + shape

p <- ggplot(data = st.kilda, mapping = aes(x = BuildingArea, y = Price/1000, shape = Type)) p + geom_point()

4. 直方图 geom_histogram()

x

h <- ggplot(data = st.kilda, mapping = aes(x = Price/1000)) h + geom_histogram()

x + fill

h <- ggplot(data = st.kilda, mapping = aes(x = Price/1000, fill = Type)) h + geom_histogram()

5. 柱状图 geom_bar() x

c <- ggplot(data = st.kilda, mapping = aes(x = Rooms)) c + geom_bar()

6. 密度函数图 geom_density() x+color

d <- ggplot(data = st.kilda, mapping = aes(x = Price/1000, color = Type)) d + geom_density()

7. 箱式图 geom_boxplot() x + y + fill

b <- ggplot(data = st.kilda, mapping = aes(x = Type, y=Price/1000, fill = Method)) b + geom_boxplot()

8. 标尺 scale

s<- ggplot(data = st.kilda, mapping = aes(x = BuildingArea, y = Price/1000, shape = Type, color = Method)) s + geom_point() + scale_y_log10()+scale_color_manual(values = rainbow(5))

坐标变换 之前

s + geom_point()

统计变换 stat_ S <-ggplot(data = st.kilda, mapping = aes(x = BuildingArea, y = Price/1000)) S + geom_point()+scale_y_log10()+stat_smooth()

坐标 coord_

x + fill

B <- ggplot(data = st.kilda, mapping = aes(x = Type, fill = Type)) B + geom_bar()+coord_flip()

B + geom_bar() + coord_polar(theta = "y")

t<- ggplot(data = st.kilda, mapping = aes(x = factor(1), fill = Type)) t + geom_bar() + coord_polar(theta = "y")

t + geom_bar() + coord_polar()

w<- ggplot(data = st.kilda, mapping = aes(x = Method, fill = Type)) w + geom_bar()+coord_polar()

分面 P <- ggplot(data = st.kilda, mapping = aes(x = BuildingArea, y = Price/1000)) P + geom_point(aes(color = Method))+scale_y_log10()+facet_wrap(~Method)+stat_smooth()

最新回复(0)