Skip to content
Prev 263184 / 398502 Next

profile plot in R

On 6/20/2011 11:25 AM, Vickie S wrote:
This works for me:

library("reshape")
library("ggplot2")

# note that the dimnames are now a named list, the names
# of which become the column names when melted.
sampledata <- matrix(c(1.002, 1.76, 0.67, 0.99, 1.38,
	1.0, 0.5, 0.78, 1.003,0.57, 0.99, 0.58, 0.76,
	1.23, 1.45, .78,1.43, 1.34, 1.0, 0.9),
	ncol = 5,
	dimnames = list(cond=c("cond1", "cond2","cond3", "cond4"),
		time = c("col1","col2", "col3", "col4", "col5")))
sdata <- melt(sampledata)   # melt method for matrices

# This works without error
ggplot(sdata, aes(time, value)) +
	geom_point(aes(colour = cond), size = 2.5) +
	geom_line(aes(colour = cond), size = 1)

# This might be what you meant, though.  By default, the group
# aesthetic is an interaction of all the categorical variables
# (here, time and cond) and a separate thing (point or line) is
# drawn for each group.  So there is only one point along each
# line (which doesn't make for much of a line).  Override this to
# make one line per cond.
ggplot(sdata, aes(time, value, colour=cond)) +
	geom_point(size = 2.5) +
	geom_line(aes(group = cond), size = 1)



 > sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods
[8] base

other attached packages:
[1] ggplot2_0.8.9 proto_0.3-9.2 reshape_0.8.4 plyr_1.5.2

loaded via a namespace (and not attached):
[1] digest_0.5.0


In particular, the most recent version of plyr is 1.5.2; I assume it 
would work with R 2.10.1, but I don't know.  You may need to install it 
as a source package.