N2015 %>% | |
group_by(Date, Treatment, Biochar, Fertilizer) %>% | |
summarise(avgNO3 = mean(NO3_N, na.rm = TRUE), | |
seNO3 = (sd(NO3_N, na.rm = TRUE)/sqrt(4))) %>% | |
ggplot(aes(x = Treatment, y = avgNO3)) + | |
geom_errorbar(aes(ymax = avgNO3 + seNO3, ymin = avgNO3 - seNO3, width = 0.2)) + | |
geom_point(aes(shape = Fertilizer, colour = Biochar), size = 6) + | |
labs(fill = "Biochar") + | |
ylab(bquote('mg'*~NO[3]^`-`~-N~kg^-1 ~ dry ~ soil*'')) + | |
scale_shape_discrete(labels = c("Compost", "Mineral")) + | |
scale_colour_manual(values = c("grey65", "grey10"), labels = c("No", "Yes")) + | |
facet_grid(~ Date) + | |
guides(colour = guide_legend(order = 2, | |
#override.aes = list(size = 20) | |
), | |
shape = guide_legend(order = 1)) + | |
theme_bw() + | |
theme(axis.title.x = element_text(size = 15), | |
axis.title.y = element_text(face = "bold", size = 15, vjust = 1), | |
axis.text.x = element_blank(), | |
axis.text.y = element_text(size = 12), | |
legend.title = element_text(size = 15), | |
legend.text = element_text(size = 12), | |
#legend.key = element_rect(size = 0.5), | |
panel.grid.minor = element_blank(), panel.grid.major = element_blank(), | |
axis.ticks.x = element_blank(), | |
strip.text.x = element_text(size = 15)) |
Hi Deirdre,
My solutions both involve changing shape elements, the codes for which can be found here.
You got close with aes.override
… you can use it to change the shape directly.
You can do this by mapping your Biochar variable to fill
and then setting the color (which is the outline of points) to “black”, but you have to use a filled-point for this, such as shape 21.
Here’s a MWE:
library(ggplot2)
d = data.frame(x = rnorm(10), y = rnorm(10), z = sample(letters[1:2], 10, TRUE))
ggplot(d, aes(x, y, fill = z)) +
geom_point(shape = 21, color = 'black', size = 5) +
guides(fill = guide_legend(override.aes = list(shape = 22)))
--
Check out our R resources at http://www.noamross.net/davis-r-users-group.html
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
Visit this group at http://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.
N2015 %>% | |
group_by(Date, Treatment, Biochar, Fertilizer) %>% | |
summarise(avgNO3 = mean(NO3_N, na.rm = TRUE), |
seNO3 = (sd(NO3_N, na.rm = TRUE) /sqrt(4))) %>% | |
ggplot(aes(x = Treatment, y = avgNO3, fill= Biochar)) + |
geom_errorbar(aes(ymax = avgNO3 + seNO3, ymin = avgNO3 - seNO3, width = 0.2)) + |
geom_point(aes(shape = Fertilizer), size = 6) + |
labs(fill = "Biochar") + | |
ylab(bquote('mg'*~NO[3]^`-`~-N~kg^-1 ~ dry ~ soil*'')) + | |
scale_shape_discrete(labels = c("Compost", "Mineral")) + |
scale_shape_manual(values = c(21, 24)) + | |
scale_fill_manual(values = c("grey70", "grey10"), labels = c("No", "Yes")) + | |
facet_grid(~ Date) + | |
guides(fill = guide_legend(order = 2, | |
override.aes = list(shape = 15, size = 9)), |
shape = guide_legend(order = 1)) + | |
theme_bw() + | |
theme(axis.title.x = element_text(size = 15), | |
axis.title.y = element_text(face = "bold", size = 15, vjust = 1), | |
axis.text.x = element_blank(), | |
axis.text.y = element_text(size = 12), | |
legend.title = element_text(size = 15), | |
legend.text = element_text(size = 12), |
legend.key = element_rect(color = "white"), |
panel.grid.minor = element_blank(), panel.grid.major = element_blank(), | |
axis.ticks.x = element_blank(), | |
strip.text.x = element_text(size = 15)) |
In that shape-guide I linked to, it looks like point-shapes 15-20 have a fill, but they don’t — they’re always solid black. So change the 15 in this line to a number between 21 and 25 and you should be good:
guides(fill = guide_legend(order = 2, override.aes = list(shape = 15, size = 9)), shape = guide_legend(order = 1))
--
Michael Levy
c: 304-376-4523