Change colour scale in stat_contour()

1,093 views
Skip to first unread message

Kevin Stierhoff - NOAA Federal

unread,
Sep 26, 2014, 5:01:07 PM9/26/14
to ggplot2
I'm having difficulty changing the color scale to anything but the default 'blues' for contour plots with geom = "polygon". I've tried scale_fill_gradient(), etc. with no success. I'm sure it's simple, but I'm stuck. Code and example plot below. Data attached.
Thanks,
Kevin

load(interp_out.Rdata)
v <- ggplot(interp.out, aes(x, y, z = z))

v + stat_contour(geom="polygon", aes(fill=..level..),binwidth=2) + stat_contour(binwidth=2) + facet_wrap(~freq) + 
  scale_x_continuous('\nAthwartship Beam Angle (deg)') + scale_y_continuous('Alongship Beam Angle (deg)\n') +
  theme_bw()

Inline image 1
interp_out.Rdata

Brandon Hurr

unread,
Sep 27, 2014, 10:02:04 AM9/27/14
to Kevin Stierhoff - NOAA Federal, ggplot2
Kevin, 

I'm not sure what your issue is, but scale_fill_gradient() works very well for me. 
See:

ggplot(interp.out, aes(x, y, z = z)) + 
stat_contour(geom="polygon", aes(fill=..level..),binwidth=2) + stat_contour(binwidth=2) + facet_wrap(~freq) + 
scale_x_continuous('\nAthwartship Beam Angle (deg)') + scale_y_continuous('Alongship Beam Angle (deg)\n') +
theme_bw()+
scale_fill_gradient(low="red", high="darkblue")

Thanks for the reproducible example! Very helpful.

B


Inline image 1

Kevin Stierhoff - NOAA Federal

unread,
Sep 29, 2014, 5:35:23 PM9/29/14
to Brandon Hurr, ggplot2
Hi Brandon,
Now I'm not sure what my problem was! Perhaps I had the scale_colour_gradient() too close to the stat_contour()? Works just fine with what you suggested, tacking it on at the end. Nonetheless, thanks for helping me sort that out. 
Kevin
--
Kevin Stierhoff
Research Fisheries Biologist
NOAA Fisheries-SWFSC
8901 La Jolla Shores Dr.

Reply all
Reply to author
Forward
0 new messages