My data are included below via dput
and look like this:
> head(dat)
General Covariate Beta SE Season
1 Intercept Intercept -4.0673077 0.0499 Summer
2 Reggedness SlopeVar_30Log 0.1835911 0.0130 Summer
3 Elevation Ele_30 0.6194081 0.0186 Summer
4 Slope Slope_500 2.3549884 0.0527 Summer
5 SlopeSq Slope_500Sq -0.6729443 0.0326 Summer
6 CanCov CanCov_1000 -0.3879034 0.0234 Summer
I have 8 estimates for Summer
and 9 for Winter
.
With these data I can make the following figure. In this instance I have General
as the x-axis and each value within General
is plotted on a single line and dodged. However, I want to label the multiple values of General
by the Covariate
name. Each level of General
has two levles of Covariate
ggplot(dat [dat $General != "Intercept",], aes(y = Beta, x = General, color = Season)) +
geom_point(position=position_dodge(0.6), size = 5)+
geom_errorbar(aes(ymin=Beta-SE, ymax=Beta+SE),width = 0.6, size = 1.2 , position=position_dodge(0.6))
If I simply change the x-axis to Covariate
(as below) then each level is on a separate line, except where the levels are identical as with Ele_30
.
ggplot(dat [dat $General != "Intercept",], aes(y = Beta, x = Covariate, color = Season)) +
geom_point(position=position_dodge(0.6), size = 3)+
geom_errorbar(aes(ymin=Beta-SE, ymax=Beta+SE),width = 0.6, size = 1.2 , position=position_dodge(0.6))+
theme(axis.text.x=element_text(angle=30, hjust=1))
Is it possible to plot each level of General
on the same vertical line (as in the first figure above), but label each point according to Covariate
(like in the bottom figure)? Said differently, I want the points plotted as in plot one, and a label under each dodged point that corresponds to Covariate
.
Thanks for any help.
library(ggplot2)
dat <- structure(list(General = structure(c(3L, 5L, 2L, 6L, 7L, 1L,
4L, 8L, 3L, 5L, 2L, 6L, 7L, 1L, 4L, 8L, 9L), .Label = c("CanCov",
"Elevation", "Intercept", "NDVI", "Reggedness", "Slope", "SlopeSq",
"Solar", "Snow"), class = "factor"), Covariate = structure(c(1L,
2L, 4L, 5L, 7L, 9L, 11L, 13L, 1L, 3L, 4L, 6L, 8L, 10L, 12L, 14L,
15L), .Label = c("Intercept", "SlopeVar_30Log", "VMR_30Log",
"Ele_30", "Slope_500", "Slope_100", "Slope_500Sq", "Slope_100Sq",
"CanCov_1000", "CanCov_30", "NDVI_MeanTin_1000", "NDVI_MeanAmp_1000",
"RadSumm_30", "AspectCos_30", "SnowSWE_1000"), class = "factor"),
Beta = c(-4.06730774504316, 0.183591094124286, 0.61940812155272,
2.35498841169247, -0.672944306628242, -0.387903359930857,
-0.815906730978726, -0.351201997266259, -5.06483998950688,
0.454499369654063, -0.337997523846132, 2.10010144558015,
0.251723125039171, -0.281294023525884, -1.02515594862923,
-0.46350259164822, -0.498134174074173), SE = c(0.0499, 0.013,
0.0186, 0.0527, 0.0326, 0.0234, 0.0152, 0.0107, 0.113, 0.0126,
0.0255, 0.0427, 0.0228, 0.0222, 0.0271, 0.0197, 0.033), Season = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L), .Label = c("Summer", "Winter"), class = "factor")), .Names = c("General",
"Covariate", "Beta", "SE", "Season"), row.names = c(NA, 17L), class = "data.frame")