How to control ggplot's plotting area proportions instead of fitting them to devices in R?

前端 未结 3 1589
星月不相逢
星月不相逢 2021-01-03 03:26

By default, each plot in ggplot fits its device.

That\'s not always desirable. For instance, one may need to make tiles in geom_tile to be

3条回答
  •  旧巷少年郎
    2021-01-03 03:45

    A cleaner way is to use the theme(aspect.ratio) argument e.g.

    library(ggplot2)
    d <- data.frame(x=rnorm(100),y=rnorm(100)*1000)
    ggplot(d,aes(x,y))+
    geom_point() +
    theme(aspect.ratio=1/10) #Long and skinny
    

    coord_fixed() sets the ratio of x/y coordinates, which isn't always the same thing (e.g. in this case, where the units of x and y are very different.

提交回复
热议问题