Line weight in geom_density plots

8,933 views
Skip to first unread message

Kevin Stierhoff

unread,
Mar 8, 2012, 11:59:53 AM3/8/12
to ggplot2
Hi,
I'm trying to adjust the line weight in a geom_density plot. My data are
attached. The code to generate the plot is below.
Thanks,
Kevin

load("lengths.Rdata")
#plot animal lengths by year
l <- ggplot(length.gg, aes(length, colour = year))
l + geom_density() + scale_colour_grey() + labs(colour="Year")
#convert to bw theme
last_plot() + theme_bw()

lengths.Rdata

Ben Bond-Lamberty

unread,
Mar 8, 2012, 12:42:09 PM3/8/12
to ggplot2
Kevin, not clear if you want to adjust it by year, or for all the
lines simultaneously:

l <- ggplot(length.gg, aes(length, size = year)) # size of line
based on variable

l + geom_density(size=2) + scale_colour_grey() + labs(colour="Year")
# constant size

Ben

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Kevin Stierhoff

unread,
Mar 8, 2012, 12:55:37 PM3/8/12
to ggp...@googlegroups.com
Dennis, yes I did mean line thickness. The default thickness was too faint to distinguish the different groups. size = 1 in geom_density did the trick.

Ben, I hadn't thought of plotting the thickness by a particular factor, but thanks for giving me options! I wanted a constant thickness in this case, though.

Thanks for the quick replies!
Kevin
--
Kevin Stierhoff, PhD
Research Fisheries Biologist
NOAA Fisheries Service - Southwest Fisheries Science Center
8604 La Jolla Shores Dr. B-115
La Jolla, CA 92037
TE: (858) 546-7180 FX: (858) 546-5656

Kevin.S...@noaa.gov
http://sites.google.com/site/kevinstierhoff/home
http://swfsc.noaa.gov/
Reply all
Reply to author
Forward
0 new messages