How about this?
df <- data.frame(x = 1:4)
df <- mutate(df, y = x, shap = factor(x), sz = c(3, 3, 10, 3))
my.shapes <- c(15,17,18,20)
# Notice that both size and shape are mapped to shap, and that
# both scales have the same title and breaks:
ggplot(df, aes(x=x, y=y, shape= shap, size = shap)) + geom_point() +
scale_shape_manual('x', breaks = levels(df$shap),
values = my.shapes) +
scale_size_manual('x', breaks = levels(df$shap),
values = df$sz)
HTH,
Dennis
> --
> 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
>
I tried your approach in a more complicated example (below), but I still couldn't manage to get it done properly.
Below are my trials. The hard part is to get only the symbol sizes changed, but not the line widths. In Trial 3, I get the desired behavior, but a second legend is added. How can I remove that?
Cheers,
Marius
require(devtools)
dev_mode(TRUE)
require(ggplot2)
require(reshape2)
## parameters of some model
p1 <- c(20, 50, 100, 200)
p2 <- c(5, 10, 20, 50, 100)
p3 <- c("group.1","group.2","group.3","group.4","group.5")
p4 <- c(0.2, 0.5, 0.8)
## replications
N <- 1000
## lengths
l1 <- length(p1)
l2 <- length(p2)
l3 <- length(p3)
l4 <- length(p4)
## build result array containing the measurements
arr <- array(rep(NA, l1*l2*l3*l4*N), dim=c(l1, l2, l3, l4, N),
dimnames=list(
p1=p1,
p2=p2,
p3=p3,
p4=p4,
N=1:N))
## fill the result array (dummy here) with values
for(i in 1:l1){
for(j in 1:l2){
for(k in 1:l3){
for(l in 1:l4){
arr[i,j,k,l,] <- i+j+k+l+runif(N)
}
}
}
}
## create molten data
mdf <- melt(arr, formula = . ~ + p1 + p2 + p3 + p4 + N) # create molten data frame
colnames(mdf) # => fine
stopifnot(dim(mdf)==c(l1*l2*l3*l4*N, 6))
## build means (dummy function here)
mdf.mean <- dcast(mdf, p1 + p2 + p3 + p4 ~ "Value", fun.aggregate=mean, value_var="value")
str(mdf.mean)
## add p1 legend labels
my.labs <- lapply(1:4, function(l) bquote(alpha==.(l)))
sym <- c(15,17,18,20)
sym.size <- c(1,1,4,1)
## plot data frame
mdf.mean. <- mdf.mean
mdf.mean.$p1 <- as.factor(mdf.mean.$p1) # convert p1 to factor
## trial 1:
ggplot(mdf.mean., aes(x=p2, y=Value, shape=p1)) + geom_point() +
geom_line(aes(group=p1)) + facet_grid(p3 ~ p4, space="free") +
scale_x_continuous(limits=c(1,max(p2)), breaks=p2, labels=p2) +
scale_shape_manual(values=sym, breaks=p1, labels=my.labs) +
scale_size_manual(values=sym.size, breaks=p1)
## => symbol sizes are not adjusted
## trial 2:
ggplot(mdf.mean., aes(x=p2, y=Value, shape=p1, size=p1)) + geom_point() +
geom_line(aes(group=p1)) + facet_grid(p3 ~ p4, space="free") +
scale_x_continuous(limits=c(1,max(p2)), breaks=p2, labels=p2) +
scale_shape_manual(values=sym, breaks=p1, labels=my.labs) +
scale_size_manual(values=sym.size, breaks=p1)
## => the line widths/sizes are changed, instead of the symbol sizes
## trial 3:
ggplot(mdf.mean., aes(x=p2, y=Value, shape=p1)) + geom_point(aes(size=p1)) +
geom_line(aes(group=p1)) + facet_grid(p3 ~ p4, space="free") +
scale_x_continuous(limits=c(1,max(p2)), breaks=p2, labels=p2) +
scale_shape_manual(values=sym, breaks=p1, labels=my.labs) +
scale_size_manual(values=sym.size, breaks=p1)
## => seems to do the job but a second legend is added