R问题。
我被width,height,dpi和unit搞糊涂了。
为什么下面两个大小不同?
ggsave(filename = "foo.png",ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(size=2, shape=23),width = 5, height = 4, dpi = 300, units = "in", device='png')和
ggsave(filename = "foo.png",ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(size=2, shape=23),width = 5, height = 4, dpi = 72, units = "in", device='png')我将两张图片的大小都设置为5(英寸)*4(英寸)。但是为什么当我改变dpi时,大小也会改变呢?
如何理解height、width、unit和dpi之间的关系
或者如何将这四个参数转换为像素单位,哪个更容易理解?
发布于 2017-06-23 09:38:33
要了解为什么DPI很重要,请考虑以下两个图:
ggsave(filename = "foo300.png", ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(size=2, shape=23) + theme_bw(base_size = 10),
width = 5, height = 4, dpi = 300, units = "in", device='png')
ggsave(filename = "foo150.png", ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(size=2, shape=23) + theme_bw(base_size = 10),
width = 10, height = 8, dpi = 150, units = "in", device='png')生成的文件具有相同的像素大小,但每个文件的字体大小不同。如果您将它们放在一个与它们的ggsave()调用具有相同物理大小的页面上,则字体大小将是正确的(即ggsave()调用中的10 )。但如果您将它们放在错误的物理大小的页面上,字体大小将不会是10。为了在增加DPI的同时保持相同的物理大小和字体大小,您必须增加图像中的像素数。
https://stackoverflow.com/questions/44711236
复制相似问题