Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom levels in ggplot2 contour plot?

Tags:

r

ggplot2

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:

enter image description here

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.

like image 727
qed Avatar asked Oct 29 '13 12:10

qed


1 Answers

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

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

enter image description here

like image 91
Didzis Elferts Avatar answered Nov 10 '22 14:11

Didzis Elferts