所以我有这样的df
df <- read.table(text="
amount nr date
50 1 2017-01-01
150 1 2017-01-03
1500 2 2017-01-04
1450 2 2017-01-04
1250 2 2017-01-04
950 1 2017-02-05
120 3 2017-02-06
300 3 2017-04-06
", header=TRUE)我用这个df创建了一个地块
ggplot(test, aes(x = date, y = amount, fill = nr, group = 1)) +
geom_bar(stat = "identity")在我用下面的代码保存这幅图之前,一切都很好。
ggsave(filename="D:/Documents/units_plot.png", width = 4, height = 2)我不知道该如何正确设置图像尺寸(应该是1000x500px),以及如何为图例、轴文本大小设置文本大小。通常,我是通过主题()选项it来完成的,但是由于某种原因,传奇在导出的文件中是如此庞大。
发布于 2019-05-10 06:37:57
一旦图像被打印出来,ggplot的大小计算就以图像的物理大小为基础。要获得特定的像素大小,您需要为DPI选择一个很好的值(每英寸像素数),并使用它来计算大小:
ggplot(test, aes(x = date, y = amount, fill = nr, group = 1)) +
geom_bar(stat = "identity") +
theme_grey(base_size = 12)
dpi = 96
ggsave(filename="units_plot.png", width = 1000 / dpi, height = 500 / dpi,
dpi = dpi)如果您选择不同的DPI值,您将不得不测试使用DPI的字体大小,而不会使标签太大或太小--我不认为有任何方法可以避免这种情况。
https://stackoverflow.com/questions/56071870
复制相似问题