On Sat, Jul 18, 2009 at 08:56:16PM -0400, Jack Monflower wrote:
> Hello everybody,
>
> I have the following R code:
>
> ===========================================
> library("ggplot2")
> c_len <- c(1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 );
> c_dep1 <- c(0 ,0 ,0.5 ,0.55,0.94,1.13,1.568,1.8432,2.10,2.355);
> c_dep2 <- c(0 ,0 ,0.58,0.62,0.91,1.15,1.57,1.799,2.007,2.08);
> c_dep3 <- c(0 ,0 ,0.42,0.93,1.42,1.864,2.25,2.610,2.9,3.23);
>
> df <- data.frame(Length = as.factor(c_len), A=c_dep1, B=c_dep2, C=c_dep3);
> dfm <- melt(df, id="Length", measure=c("A", "B", "C"));
>
> p <- qplot(Length, value, data=dfm, colour=variable, geom="line")
> ## adding geom="line" does not work
> print(p)
> ==========================================
>
> Whatever I do to draw lines (using geom="line") instead of dots, does not
> work. Instead I get an empty
You use a factor variable for the x axis, because of this the space
between two values is not defined. Remove the as.factor and everything
works as expected.
>...
> Another point: I want to use this plot in a slide. I would like it to be
> quite
> "fancy". One way I thought it could be done is by using thick lines
> surrounded
> with some border instead of just plain thin line and circles on the lines).
> Is there a way to do it?
Maybe one of the themes in the ggplot-add-ons package?
http://r-forge.r-project.org/projects/ggplot-add-ons/
regards,
stefan
The default grouping in ggplot2 is defined by the combination of all
categorical variables in the plot. This works well most of the time,
but if you are drawing lines and have a categorical variable on the x
axis, you will need to manually specify the grouping:
qplot(Length, value, data=dfm, colour=variable, geom="line", group = variable)
Hadley