ggplot2等高线图中的自定义级别? [英] Custom levels in ggplot2 contour plot?

查看:785
本文介绍了ggplot2等高线图中的自定义级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 #生成数据
library(reshape2)#for融化
volcano3d< - 熔化(火山)
名称(volcano3d)< -c(x,y,z)

#基本图
v < - ggplot(volcano3d,aes(x,y,z = z))
v + stat_contour(binwidth = 10)

输出:





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

解决方案

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

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


Here is a code snippet from the docs site:

# 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)

Output:

What if I want to draw contour lines at custom levels? For example, in the volcano3d data set, I want these levels to be indicate: z == 120, 140, 160.

解决方案

Replace binwidth= with argument breaks= and provide breakpoint you need.

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

这篇关于ggplot2等高线图中的自定义级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆