如何减少ggplot中geom_point()之间的相对距离

雅各布

我有一个显示大量信息的图表,我不想在空白处浪费空间。有什么方法可以减少 x 轴上点之间的绘制距离。理想情况下,我希望它们几乎可以接触。我可能可以做到这一点,将图中的每个尺寸参数(点、轴标签、注释、图例条目等)都更改为巨大的值,但我想知道是否有更简单的方法可以按照 position.dodge 左右的线进行操作?

这是一个以两种不同尺寸保存的示例,以表明它们仍然具有较高的相对距离:

library(ggplot)

plotdata <- data.frame(my_y = rnorm(3),
                       my_x = 1:3)

pdf("yourpath/test.pdf",
    width = 4, height = 4)
ggplot(plotdata, aes(x = my_x, y = my_y)) + geom_point()
dev.off()

pdf("yourpath/test2.pdf",
    width = 2, height = 2)
ggplot(plotdata, aes(x = my_x, y = my_y)) + geom_point()
dev.off()

我的回答采用与@Quinten 类似的方法,但为任何数据构建了一个函数:

xmax<-max(plotdata$my_x);ymax=max(plotdata$my_y)
xmin<-min(plotdata$my_x);ymin=min(plotdata$my_y)

pdf("C:/temp/test.pdf",
   width = 4, height = 4)
ggplot(plotdata, aes(x = my_x, y = my_y)) + geom_point()+
  xlim(xmin-0.1,xmax+0.1)+
  ylim(ymin-0.1,ymax+0.1)

dev.off()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

ggplot2减少geom_point()因子之间的空间

如何更改geom_point中的颜色或ggplot中的线

如何减少div中图像之间的距离?

如何添加相对于geom_point大小的位置的geom_text或geom_label?

无论如何要更改 R (geom_point) 中 ggplot 中值的大小?

如何更改ggplot2的geom_point中缺失值的颜色?

如何在R中为我的数据构建ggplot geom_point()?

在geom_point中使用cut时如何在ggplot中添加椭圆

如何使用geom_point在gganimate中创建状态之间的平滑过渡?

如何使用ggplot按geom_point显示比例?

从图例中删除ggplot2的geom_point图标

增加ggplot geom_point中的最小点大小

ggplot2 2.0.0中的geom_point边界

ggplot中的自定义形状(geom_point)

ggplot:geom_point中的颜色,填充和大小

ggplot图例(geom_point)中的空白条目?

ggplot2 中的振幅线 + geom_point

geom_point {ggplot2}中的alpha值

如何在ggplot2中获取堆叠的geom_bar和geom_point的通用图例?

ggplot方面和条件geom_point

ggplot,条件填充 geom_point

ggplot,基于变量的geom_point颜色

如何强制geom_point在R中显示比例大小?

如何根据python中的条件添加geom_point层

有人可以解释ggplot和geom_point之间的区别吗?

ggplot2中带有geom_line和geom_point的图例

使用geom_bar和geom_point控制ggplot中的图例

使用geom_point()和geom_line()进行多个系列的ggplot中的图例错误

為 ggplot2 中的特定 geom_area 添加 geom_point