数据科学与R语言大数据数据可视化 在线画图

可视化 坐标系统

2018-06-17  本文已影响13人  柳叶刀与小鼠标

坐标系可能是ggplot2中最复杂的部分。 默认坐标系是笛卡尔坐标系,其中x和y位置独立地确定每个点的位置。 还有一些偶尔有用的其他坐标系统。

ggplot2可以通过coord_flip()切换x和y轴。例如,如果你想要水平箱形图。 这对长标签也很有用:很难让它们在x轴上不重叠的情况下适合。

ggplot(data = mpg, mapping = aes(x = class, y = hwy)) + 
  geom_boxplot()
ggplot(data = mpg, mapping = aes(x = class, y = hwy)) + 
  geom_boxplot() +
  coord_flip()

nz <- map_data("nz")

ggplot(nz, aes(long, lat, group = group)) +
  geom_polygon(fill = "white", colour = "black")

ggplot(nz, aes(long, lat, group = group)) +
  geom_polygon(fill = "white", colour = "black") +
  coord_quickmap()

bar <- ggplot(data = diamonds) + 
  geom_bar(
    mapping = aes(x = cut, fill = cut), 
    show.legend = FALSE,
    width = 1
  ) + 
  theme(aspect.ratio = 1) +
  labs(x = NULL, y = NULL)

bar + coord_flip()
bar + coord_polar()

上一篇 下一篇

猜你喜欢

热点阅读