r - ggplot2 等高线图中的自定义级别?

标签 r ggplot2

这是来自文档站点的代码片段:

# Generate data
library(reshape2) # for melt
volcano3d <- melt(volcano)
names(volcano3d) <- c("x", "y", "z")

# Basic plot
v <- ggplot(volcano3d, aes(x, y, z = z))
v + stat_contour(binwidth = 10)

输出:

enter image description here

如果我想在自定义级别绘制轮廓线怎么办?例如,在vocabulary3d 数据集中,我希望指示这些级别:z == 120、140、160。

最佳答案

替换 binwidth=带参数 breaks=并提供您需要的断点。

ggplot(volcano3d, aes(x, y, z = z)) + 
  stat_contour(breaks=c(120,140,160))

enter image description here

关于r - ggplot2 等高线图中的自定义级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19658088/

相关文章:

python - 在 Python 或 R 中合并具有不同 header 的数据

r - ggplot2 中带有 geom_line 和 geom_point 的图例

r - ggplot2 中的嵌套 facet_wrap()

r - 您可以通过调用向量中的字符来分配 ggplot2 美学吗?

r - 如何在 R 中正确使用 summarise 来进行这个简单的分析?

r - 使用 ggplot2 对核密度图的 facet.grid 进行着色

r - 通过命令使用 R 中的不同最大值

r - 如何根据 R 中的一个有序列表绘制有向箭头?

r - 有没有办法将本地存储的图像读取到 Plotly 中?

r - 在 R 中的 igraph 中,是否可以在顶点对象周围创建虚线?