繁体   English   中英

如何将 plot 图表按 ggplot2 固定刻度?

[英]How to plot chart by ggplot2 with fixed scale?

我需要在 R 中使用 ggplot2 绘制不同类型的图片,打印时必须按适当的比例绘制。 这意味着我必须定义精确的图像和图表大小,相同的 x/y 轴比例。

你能告诉我应该使用什么样的选项吗?

ggplot(Surface, aes(x, y, z = z)) +
  geom_contour_filled(binwidth = 10, alpha = 0.6) +
  geom_textcontour(binwidth = 20, size = 2.5)

如果你的意思是来自geom_text_contour metR的 geom_text_contour 那么我们可以这样做:

这个例子取自这里How to add labels in a contour plot using ggplot2? (学分@bbiasi)

library(metR)
library(tidyverse)
library(data.table)

v <- data.table::melt(volcano)
ggplot(v, aes(Var1, Var2)) +
  ggplot2::geom_contour(aes(z = value))+
  metR::geom_text_contour(aes(z = value)) 

# adding ggsave with width and height
ggsave("test_myplot.png", width = 9, height = 7)

在此处输入图像描述

也许您想将coord_fixedratio参数一起使用:

纵横比,表示为 y / x

这是您的代码:

library(ggplot2)
ggplot(Surface, aes(x, y, z = z)) +
  geom_contour_filled(binwidth = 10, alpha = 0.6) +
  geom_textcontour(binwidth = 20, size = 2.5) +
  coord_fixed(ratio = 2/1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM