[R] a very particular plot

Hadley Wickham hadley at rice.edu
Fri Jul 16 12:06:43 CEST 2010


On Wed, Jul 14, 2010 at 1:32 AM, Ian Bentley <ian.bentley at gmail.com> wrote:
> I've got a couple of more changes that I want to make to my plot, and I
> can't figure things out.  Thanks for all the help.
>
> I'm using this R script
>
> library(ggplot2)
> library(lattice)
> # Generate 50 data sets of size 100 and assign them to a list object
>
> low <- 1
> n <- 50
> #Load data from file
> for(i in low:n) assign(paste('df', i, sep = ''),
>         read.table(paste("tot-LinkedList",i*100,"query.log",sep=''),
> header=TRUE))
>
>
> dnames <- paste('df', low:n, sep = '')
> l <- vector('list', n)
> for(i in seq_along(dnames)) l[[i]] <- with(get(dnames[i]), Send + Receive)
> ml <- melt(l)
>
> dsum <- ddply(ml, 'L1', summarise, mins = min(value), meds = median(value),
>               maxs = max(value))
>
>
> p <- ggplot(ml, aes(x = L1*100, y = value)) +
>     geom_point(alpha = 0.2) +
>     geom_point(data = dsum, aes(y = mins), shape = 1, size = 3, solid=TRUE,
> colour='blue') +
>     geom_point(data = dsum, aes(y = meds), shape = 2, size = 3, solid=TRUE,
> colour='blue') +
>     geom_point(data = dsum, aes(y = maxs), shape = 3, size = 3, solid=TRUE,
> colour='blue') +
>     geom_smooth(data = dsum, aes(y = mins)) +
>     geom_smooth(data = dsum, aes(y = meds)) +
>     geom_smooth(data = dsum, aes(y = maxs)) +
>     opts(axis.text.x = theme_text(size = 7, angle = 90, hjust = 1), title =
> 'Linked List Query Costs Increasing Network Size')  +
>     xlab('Network Complexity (nodes)') + ylab('Battery Cost (uJ)') +
>
> --END--
>
> And this works great, except that I think that I am not being very R'y,
> since now I want to add a legend saying that circle (i.e. shape 1) is the
> minimum, and shape 2 is the med, and shape 3 is max.
>
> I'd also like to be able to move the legend to the top left part of the plot
> since that area is empty anyways.
>
> Is there any way that I can do it easily?

Yes, but it's difficult to show you how without a simple reproducible example...

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list