how to add several point range plots in only one graph, to present the results from multiple model?

68 views
Skip to first unread message

Antonio Pedro

unread,
Nov 26, 2012, 11:54:46 PM11/26/12
to ggp...@googlegroups.com
Hi all, 

I would like to combine all these 3 plots in just one plot, where I could have for each coefficient three point ranges, each one from each model. I think these type of presentation of multiple coefficient in just one plot is becoming quite standard now but I don't know how to so them with the terrific ggplot. I really appreciate any help. Thanks in advance! 


Antonio Pedro. 

limits1 <-aes(ymax=res1[,3], ymin=res1[,1])
p1 <- qplot(rownames(res1),res1[,2],main=expression("Fixed Effects Estimates From the Main Models")) + 
      geom_pointrange(limits1) + coord_flip()
limits2 <-aes(ymax=res2[,3], ymin=res2[,1])
p2 <- qplot(rownames(res2),res2[,2],main=expression("Fixed Effects Estimates From the Main Models")) + 
  geom_pointrange(limits2) + coord_flip()
limits3 <-aes(ymax=res3[,3], ymin=res3[,1])
p3 <- qplot(rownames(res3),res3[,2],main=expression("Fixed Effects Estimates From the Main Models")) + 
  geom_pointrange(limits3) + coord_flip()

pushViewport(viewport(layout = grid.layout(1, 3)))
print(p1, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(p2, vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
print(p3, vp = viewport(layout.pos.row = 1, layout.pos.col = 3))


> dput(res1)
structure(c(0.0398717191353306, 0.0753029476141652, 0.132348061127602, 
0.106061093195025, 0.118730388402611, 0.186252499812586, 0.0884268166121857, 
0.196565415453796, 0.0818643229703002, 0.135371557953115, -0.036872, 
-0.005948, -0.006648, -0.004464, 0.01174, -0.08346, 0.599704, 
-0.034392, -0.04178, -0.03178, -0.043392, -0.0431, -0.027956, 
-0.03348, -0.034816, -0.055468, -0.03296, 0.0532690389141655, 
0.103871574862124, 0.196636191742327, 0.162919347702524, 0.154694975642655, 
0.223800555719435, 0.109273649176234, 0.243144344915242, 0.150363437311916, 
0.216340872886065, -0.0306, -0.0034, 8e-04, -0.0027, 0.0186, 
-0.0619, 0.8547, -0.0242, -0.032372, -0.021, -0.031828, -0.034672, 
-0.0209, -0.026228, -0.027172, -0.0392, -0.019828, 0.0711679999853447, 
0.143278641888225, 0.292152310910291, 0.250258724063961, 0.201553585489284, 
0.268918209370221, 0.135035172154384, 0.300760804375368, 0.276178467736878, 
0.345740080034496, -0.024328, -0.000852, 0.008248, -0.000936, 
0.02546, -0.04034, 1.109696, -0.014008, -0.022964, -0.01022, 
-0.020264, -0.026244, -0.013844, -0.018976, -0.019528, -0.022932, 
-0.006696), .Dim = c(27L, 3L), .Dimnames = list(c("Democracies, High Income", 
"Democracies, Middle Income", "Democracies, Low Income", "Dictatorships, High Income", 
"Dictatorships, Middle Income", "Dictatorships, Low Income", 
"One Transition, Middle Income", "One Transition, Low Income", 
"Many Transitions, Middle Income", "Many Transitions, Low Income", 
"High Income Democacies:time", "my.new.time.one.transition.low", 
"demo.one.time.transit.low.income", "my.new.time.one.transition.middle", 
"demo.one.time.transit.middle.income", "maternal_educ", "hiv_prev", 
"log(IHME_usd_gdppc)", "Democracies, Middle Income:time", "Democracies, Low Income:time", 
"Dictatorships, High Income:time", "Dictatorships, Middle Income:time", 
"Dictatorships, Low Income:time", "One Transition, Middle Income:time", 
"One Transition, Low Income:time", "Many Transitions, Middle Income:time", 
"Many Transitions, Low Income:time"), c("low", "mean", "upper"
)))
> dput(res2)
structure(c(0.0273056947402751, 0.0562246503455014, 0.112056507911263, 
0.083823322396034, 0.0932745485384253, 0.160848556425517, 0.0659947556474458, 
0.170147767312342, 0.0605726383648713, 0.114474864969832, -0.042676, 
-0.006048, -0.006452, -0.003764, 0.01134, 0.560684, -0.032792, 
-0.0075, -0.004372, -0.023752, -0.00972, 0.000652, -0.012144, 
0.000664, -0.030752, -0.00892, 0.0359977083318809, 0.0788427434193709, 
0.173721819086456, 0.133881526594014, 0.123279641005498, 0.195753316837873, 
0.0807578587203961, 0.214338229494029, 0.118457622310535, 0.192434392794008, 
-0.0366, -0.0035, 8e-04, -0.002, 0.0182, 0.8147, -0.0226, 0.0023, 
0.0068, -0.0116, -9e-04, 0.0081, -0.0045, 0.0087, -0.0137, 0.0048, 
0.0474565843305885, 0.110559659361049, 0.269321889368585, 0.21383384302591, 
0.162936943942255, 0.238232545598088, 0.0988234850045371, 0.270005756456979, 
0.231659189070478, 0.323485819701621, -0.030524, -0.000952, 0.008052, 
-0.000236, 0.02506, 1.068716, -0.012408, 0.0121, 0.017972, 0.000552, 
0.00792, 0.015548, 0.003144, 0.016736, 0.003352, 0.01852), .Dim = c(26L, 
3L), .Dimnames = list(c("Democracies, High Income", "Democracies, Middle Income", 
"Democracies, Low Income", "Dictatorships, High Income", "Dictatorships, Middle Income", 
"Dictatorships, Low Income", "One Transition, Middle Income", 
"One Transition, Low Income", "Many Transitions, Middle Income", 
"Many Transitions, Low Income", "High Income Democacies:time", 
"my.new.time.one.transition.low", "demo.one.time.transit.low.income", 
"my.new.time.one.transition.middle", "demo.one.time.transit.middle.income", 
"hiv_prev", "log(IHME_usd_gdppc)", "Democracies, Middle Income:time", 
"Democracies, Low Income:time", "Dictatorships, High Income:time", 
"Dictatorships, Middle Income:time", "Dictatorships, Low Income:time", 
"One Transition, Middle Income:time", "One Transition, Low Income:time", 
"Many Transitions, Middle Income:time", "Many Transitions, Low Income:time"
), c("low", "mean", "upper")))
> dput(res3)
structure(c(0.0316361128244578, 0.0617147695434284, 0.111643111485216, 
0.0833332208157427, 0.0988120221451353, 0.16128214408656, 0.073591628715114, 
0.169013615874449, 0.0664352161093451, 0.116239797710042, -0.037472, 
-0.006148, -0.006548, -0.004564, 0.01224, -0.081452, 0.599612, 
-0.005204, -0.001376, -0.018856, -0.006424, 0.002348, -0.009348, 
0.00196, -0.02556, -0.008928, 0.0417147706777615, 0.084728775556279, 
0.166460039728045, 0.127581487612948, 0.127888050912028, 0.19239590976388, 
0.089860213448317, 0.207878812767844, 0.123008723913358, 0.186971328016159, 
-0.0312, -0.0036, 9e-04, -0.0028, 0.0191, -0.0595, 0.855, 0.0044, 
0.0096, -0.0069, 0.0022, 0.0096, -0.0019, 0.0098, -0.0089, 0.0044, 
0.0550042953239485, 0.116324916391602, 0.248192158545598, 0.195324695507964, 
0.165519875122631, 0.229511991569287, 0.109725224213154, 0.255681180324957, 
0.227757912819737, 0.300742759268464, -0.024928, -0.001052, 0.008348, 
-0.001036, 0.02596, -0.037548, 1.110388, 0.014004, 0.020576, 
0.005056, 0.010824, 0.016852, 0.005548, 0.01764, 0.00776, 0.017728
), .Dim = c(26L, 3L), .Dimnames = list(c("Democracies, High Income", 
"Democracies, Middle Income", "Democracies, Low Income", "Dictatorships, High Income", 
"Dictatorships, Middle Income", "Dictatorships, Low Income", 
"One Transition, Middle Income", "One Transition, Low Income", 
"Many Transitions, Middle Income", "Many Transitions, Low Income", 
"High Income Democacies:time", "my.new.time.one.transition.low", 
"demo.one.time.transit.low.income", "my.new.time.one.transition.middle", 
"demo.one.time.transit.middle.income", "maternal_educ", "hiv_prev", 
"Democracies, Middle Income:time", "Democracies, Low Income:time", 
"Dictatorships, High Income:time", "Dictatorships, Middle Income:time", 
"Dictatorships, Low Income:time", "One Transition, Middle Income:time", 
"One Transition, Low Income:time", "Many Transitions, Middle Income:time", 
"Many Transitions, Low Income:time"), c("low", "mean", "upper"
)))
test.png

Dennis Murphy

unread,
Nov 27, 2012, 2:22:23 AM11/27/12
to Antonio Pedro, ggp...@googlegroups.com
Hi:

Here's one approach to what I think you want:

# Convert the matrices to data frames, create some
# new variables and row concatenate the results
resDF <- ldply(lapply(paste0("res", 1:3), function(x) {
d <- as.data.frame(get(x))
d$category <- rownames(d)
rownames(d) <- NULL
d$set <- substring(x, 4, 4)
d } ), rbind)

# Plot
ggplot(resDF, aes(x = category, y = mean, color = set)) +
geom_pointrange(aes(ymin = low, ymax = upper),
position = position_dodge(width = 0.8)) +
labs(y = "Effect", x = "") +
coord_flip() +
ggtitle("Fixed effects estimates from the main model") +
scale_color_manual(values = c("blue", "orange", "forestgreen"))

There appears to be a relationship between the size of the effect and
the length of the pointrange; you may want to check into that further.

Dennis

Antonio P. Ramos

unread,
Nov 27, 2012, 1:49:40 PM11/27/12
to Dennis Murphy, ggp...@googlegroups.com
Thanks Dennis. Everything works fine. I also need to have different symbols for each group so I tried to add 

scale_shape_manual(values=c(21,24,30)) 

to your original code. Yet, this is not changing the symbols. Any clue why?

Thanks a bunch!

Dennis Murphy

unread,
Nov 27, 2012, 5:31:28 PM11/27/12
to Antonio P. Ramos, ggp...@googlegroups.com
Hi:

There is no pch value 30, so this code yields warnings; replace it
with a valid value and you'll be fine. You probably didn't map the
shape aesthetic before creating a scale for it.

ggplot(resDF, aes(x = category, y = mean, color = set, shape = set)) +
geom_pointrange(aes(ymin = low, ymax = upper),
position = position_dodge(width = 0.8)) +
labs(y = "Effect", x = "") +
coord_flip() +
ggtitle("Fixed effects estimates from the main model") +
scale_color_manual(values = c("blue", "orange", "forestgreen")) +
scale_shape_manual(values = c(21, 24, 30))

Dennis

Antonio P. Ramos

unread,
Nov 27, 2012, 5:41:29 PM11/27/12
to Dennis Murphy, ggp...@googlegroups.com
thanks

Antonio P. Ramos

unread,
Nov 28, 2012, 8:59:13 PM11/28/12
to Dennis Murphy, ggp...@googlegroups.com
This is basically a follow up from the previous question. I am sorry, I really can't understand this error message:

> ggplot(resDF, aes(x = coef.name, y = mean, color = model)) +
+   geom_pointrange(aes(ymin = low, ymax = upper),
+                   position = position_dodge(width = 0.8)) +
+   labs(y = "Effect", x = "") +
+   coord_flip() +
+   ggtitle("Fixed effects estimates from the main model") +
+   scale_color_manual(values = c("blue", "orange", "forestgreen"))
Error in data.frame(ymin = c(-0.5948, -0.6648, -0.4464, 1.174, -8.346,  : 
  arguments imply differing number of rows: 79, 0


Any ideas? Thanks in advance

> dput(resDF)
structure(list(model = c("1", "1", "1", "1", "1", "1", "1", "1", 
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", 
"1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", 
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", 
"2", "2", "2", "2", "2", "2", "3", "3", "3", "3", "3", "3", "3", 
"3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", 
"3", "3", "3", "3", "3", "3"), category = c("my.new.time.one.transition.low", 
"demo.one.time.transit.low.income", "my.new.time.one.transition.middle", 
"demo.one.time.transit.middle.income", "maternal_educ", "hiv_prev", 
"log(IHME_usd_gdppc)", "High Income Democacies:time", "Democracies, Middle Income:time", 
"Democracies, Low Income:time", "Dictatorships, High Income:time", 
"Dictatorships, Middle Income:time", "Dictatorships, Low Income:time", 
"One Transition, Middle Income:time", "One Transition, Low Income:time", 
"Many Transitions, Middle Income:time", "Many Transitions, Low Income:time", 
"Democracies, High Income", "Democracies, Middle Income", "Democracies, Low Income", 
"Dictatorships, High Income", "Dictatorships, Middle Income", 
"Dictatorships, Low Income", "One Transition, Middle Income", 
"One Transition, Low Income", "Many Transitions, Middle Income", 
"Many Transitions, Low Income", "my.new.time.one.transition.low", 
"demo.one.time.transit.low.income", "my.new.time.one.transition.middle", 
"demo.one.time.transit.middle.income", "hiv_prev", "log(IHME_usd_gdppc)", 
"Democracies, High Income", "Democracies, Middle Income", "Democracies, Low Income", 
"Dictatorships, High Income", "Dictatorships, Middle Income", 
"Dictatorships, Low Income", "One Transition, Middle Income", 
"One Transition, Low Income", "Many Transitions, Middle Income", 
"Many Transitions, Low Income", "High Income Democacies:time", 
"Democracies, Middle Income:time", "Democracies, Low Income:time", 
"Dictatorships, High Income:time", "Dictatorships, Middle Income:time", 
"Dictatorships, Low Income:time", "One Transition, Middle Income:time", 
"One Transition, Low Income:time", "Many Transitions, Middle Income:time", 
"Many Transitions, Low Income:time", "Dictatorships, Low Income", 
"One Transition, Middle Income", "One Transition, Low Income", 
"Many Transitions, Middle Income", "Many Transitions, Low Income", 
"High Income Democacies:time", "my.new.time.one.transition.low", 
"demo.one.time.transit.low.income", "my.new.time.one.transition.middle", 
"demo.one.time.transit.middle.income", "hiv_prev", "log(IHME_usd_gdppc)", 
"Democracies, High Income", "Democracies, Middle Income", "Democracies, Low Income", 
"Dictatorships, High Income", "Dictatorships, Middle Income", 
"Democracies, Middle Income:time", "Democracies, Low Income:time", 
"Dictatorships, High Income:time", "Dictatorships, Middle Income:time", 
"Dictatorships, Low Income:time", "One Transition, Middle Income:time", 
"One Transition, Low Income:time", "Many Transitions, Middle Income:time", 
"Many Transitions, Low Income:time"), coef.type = c("Predictors", 
"Predictors", "Predictors", "Predictors", "Predictors", "Predictors", 
"Predictors", "Group.Intercepts", "Group.Intercepts", "Group.Intercepts", 
"Group.Intercepts", "Group.Intercepts", "Group.Intercepts", "Group.Intercepts", 
"Group.Intercepts", "Group.Intercepts", "Group.Intercepts", "Group.Slopes", 
"Group.Slopes", "Group.Slopes", "Group.Slopes", "Group.Slopes", 
"Group.Slopes", "Group.Slopes", "Group.Slopes", "Group.Slopes", 
"Group.Slopes", "Predictors", "Predictors", "Predictors", "Predictors", 
"Predictors", "Predictors", "Group.Intercepts", "Group.Intercepts", 
"Group.Intercepts", "Group.Intercepts", "Group.Intercepts", "Group.Intercepts", 
"Group.Intercepts", "Group.Intercepts", "Group.Intercepts", "Group.Intercepts", 
"Group.Slopes", "Group.Slopes", "Group.Slopes", "Group.Slopes", 
"Group.Slopes", "Group.Slopes", "Group.Slopes", "Group.Slopes", 
"Group.Slopes", "Group.Slopes", "Predictors", "Predictors", "Predictors", 
"Predictors", "Predictors", "Predictors", "Group.Intercepts", 
"Group.Intercepts", "Group.Intercepts", "Group.Intercepts", "Group.Intercepts", 
"Group.Intercepts", "Group.Intercepts", "Group.Intercepts", "Group.Intercepts", 
"Group.Intercepts", "Group.Slopes", "Group.Slopes", "Group.Slopes", 
"Group.Slopes", "Group.Slopes", "Group.Slopes", "Group.Slopes", 
"Group.Slopes", "Group.Slopes", "Group.Slopes"), coef.name = c("my.new.time.one.transition.low", 
"demo.one.time.transit.low.income", "my.new.time.one.transition.middle", 
"demo.one.time.transit.middle.income", "maternal_educ", "hiv_prev", 
"log(IHME_usd_gdppc)", "High Income Democacies:time", "Democracies, Middle Income:time", 
"Democracies, Low Income:time", "Dictatorships, High Income:time", 
"Dictatorships, Middle Income:time", "Dictatorships, Low Income:time", 
"One Transition, Middle Income:time", "One Transition, Low Income:time", 
"Many Transitions, Middle Income:time", "Many Transitions, Low Income:time", 
"Democracies, High Income", "Democracies, Middle Income", "Democracies, Low Income", 
"Dictatorships, High Income", "Dictatorships, Middle Income", 
"Dictatorships, Low Income", "One Transition, Middle Income", 
"One Transition, Low Income", "Many Transitions, Middle Income", 
"Many Transitions, Low Income", NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), coef.group = c("One Time Transition, Low Income", 
"One Time Transition, Low Income", "One Time Transition, Middle Income", 
"One Time Transition, Middle Income", "maternal education", "hiv_prev", 
"log(IHME_usd_gdppc)", "Democracies, High Income", "Democracies, Middle Income", 
"Democracies, Low Income", "Dictatorships, High Income", "Dictatorships, Middle Income", 
"Dictatorships, Low Income", "One Transition, Middle Income", 
"One Transition, Low Income", "Many Transitions, Middle Income", 
"Many Transitions, Low Income", "High Income Democacies", "Democracies, Middle Income", 
"Democracies, Low Income", "Dictatorships, High Income", "Dictatorships, Middle Income", 
"Dictatorships, Low Income", "One Transition, Middle Income", 
"One Transition, Low Income", "Many Transitions, Middle Income", 
"Many Transitions, Low Income", "One Time Transition, Low Income", 
"One Time Transition, Low Income", "One Time Transition, Middle Income", 
"One Time Transition, Middle Income", "hiv_prev", "log(IHME_usd_gdppc)", 
"Democracies, High Income", "Democracies, Middle Income", "Democracies, Low Income", 
"Dictatorships, High Income", "Dictatorships, Middle Income", 
"Dictatorships, Low Income", "One Transition, Middle Income", 
"One Transition, Low Income", "Many Transitions, Middle Income", 
"Many Transitions, Low Income", "High Income Democacies", "Democracies, Middle Income", 
"Democracies, Low Income", "Dictatorships, High Income", "Dictatorships, Middle Income", 
"Dictatorships, Low Income", "One Transition, Middle Income", 
"One Transition, Low Income", "Many Transitions, Middle Income", 
"Many Transitions, Low Income", "One Time Transition, Low Income", 
"One Time Transition, Low Income", "One Time Transition, Middle Income", 
"One Time Transition, Middle Income", "hiv_prev", "log(IHME_usd_gdppc)", 
"Democracies, High Income", "Democracies, Middle Income", "Democracies, Low Income", 
"Dictatorships, High Income", "Dictatorships, Middle Income", 
"Dictatorships, Low Income", "One Transition, Middle Income", 
"One Transition, Low Income", "Many Transitions, Middle Income", 
"Many Transitions, Low Income", "High Income Democacies", "Democracies, Middle Income", 
"Democracies, Low Income", "Dictatorships, High Income", "Dictatorships, Middle Income", 
"Dictatorships, Low Income", "One Transition, Middle Income", 
"One Transition, Low Income", "Many Transitions, Middle Income", 
"Many Transitions, Low Income"), low = c(-0.5948, -0.6648, -0.4464, 
1.174, -8.346, 59.9704, -3.4392, -3.6872, -4.178, -3.178, -4.3392, 
-4.31, -2.7956, -3.348, -3.4816, -5.5468, -3.296, 0.0398717191353306, 
0.0753029476141652, 0.132348061127602, 0.106061093195025, 0.118730388402611, 
0.186252499812586, 0.0884268166121857, 0.196565415453796, 0.0818643229703002, 
0.135371557953115, -0.6048, -0.6452, -0.3764, 1.134, 56.0684, 
-3.2792, 0.0273056947402751, 0.0562246503455014, 0.112056507911263, 
0.083823322396034, 0.0932745485384253, 0.160848556425517, 0.0659947556474458, 
0.170147767312342, 0.0605726383648713, 0.114474864969832, -4.2676, 
-5.0176, -4.0972, -5.4276, -5.2396, -3.5948, -4.2668, -4.2012, 
-6.7352, -3.9444, 0.160848556425517, 0.0659947556474458, 0.170147767312342, 
0.0605726383648713, 0.114474864969832, -4.2676, -0.6048, -0.6452, 
-0.3764, 1.134, 56.0684, -3.2792, 0.0273056947402751, 0.0562246503455014, 
0.112056507911263, 0.083823322396034, 0.0932745485384253, -5.0176, 
-4.0972, -5.4276, -5.2396, -3.5948, -4.2668, -4.2012, -6.7352, 
-3.9444), mean.median = c(-0.34, 0.08, -0.27, 1.86, -6.19, 85.47, 
-2.42, -3.06, -3.2372, -2.1, -3.1828, -3.4672, -2.09, -2.6228, 
-2.7172, -3.92, -1.9828, 0.0532690389141655, 0.103871574862124, 
0.196636191742327, 0.162919347702524, 0.154694975642655, 0.223800555719435, 
0.109273649176234, 0.243144344915242, 0.150363437311916, 0.216340872886065, 
-0.35, 0.08, -0.2, 1.82, 81.47, -2.26, 0.0359977083318809, 0.0788427434193709, 
0.173721819086456, 0.133881526594014, 0.123279641005498, 0.195753316837873, 
0.0807578587203961, 0.214338229494029, 0.118457622310535, 0.192434392794008, 
-3.66, -4.0376, -2.98, -4.2124, -4.3576, -2.85, -3.5024, -3.3976, 
-5.03, -2.5724, 0.195753316837873, 0.0807578587203961, 0.214338229494029, 
0.118457622310535, 0.192434392794008, -3.66, -0.35, 0.08, -0.2, 
1.82, 81.47, -2.26, 0.0359977083318809, 0.0788427434193709, 0.173721819086456, 
0.133881526594014, 0.123279641005498, -4.0376, -2.98, -4.2124, 
-4.3576, -2.85, -3.5024, -3.3976, -5.03, -2.5724), upper = c(-0.0852, 
0.8248, -0.0936, 2.546, -4.034, 110.9696, -1.4008, -2.4328, -2.2964, 
-1.022, -2.0264, -2.6244, -1.3844, -1.8976, -1.9528, -2.2932, 
-0.6696, 0.0711679999853447, 0.143278641888225, 0.292152310910291, 
0.250258724063961, 0.201553585489284, 0.268918209370221, 0.135035172154384, 
0.300760804375368, 0.276178467736878, 0.345740080034496, -0.0952, 
0.8052, -0.0236, 2.506, 106.8716, -1.2408, 0.0474565843305885, 
0.110559659361049, 0.269321889368585, 0.21383384302591, 0.162936943942255, 
0.238232545598088, 0.0988234850045371, 0.270005756456979, 0.231659189070478, 
0.323485819701621, -3.0524, -3.0576, -1.8628, -2.9972, -3.4756, 
-2.1052, -2.738, -2.594, -3.3248, -1.2004, 0.238232545598088, 
0.0988234850045371, 0.270005756456979, 0.231659189070478, 0.323485819701621, 
-3.0524, -0.0952, 0.8052, -0.0236, 2.506, 106.8716, -1.2408, 
0.0474565843305885, 0.110559659361049, 0.269321889368585, 0.21383384302591, 
0.162936943942255, -3.0576, -1.8628, -2.9972, -3.4756, -2.1052, 
-2.738, -2.594, -3.3248, -1.2004)), .Names = c("model", "category", 
"coef.type", "coef.name", "coef.group", "low", "mean.median", 
"upper"), class = "data.frame", row.names = c(NA, -79L))

Joshua Wiley

unread,
Nov 28, 2012, 9:15:43 PM11/28/12
to Antonio P. Ramos, Dennis Murphy, ggplot2
Hi Antonio,
 
That error message typically comes when there is some sort of mismatch in your data.  For example you could be using variables from different datasets that have an unequal number of rows.  When you see the particular values 79, 0, the zero is a give away that for some variable, there is no data.  That can cue you in to look for missing variables or misspelled variable names.  In your case, you use mean, but the variable is called mean.median.  ggplot does not find a variable mean, so there is 0 rows of data for that.  This code works for me:
 
ggplot(resDF, aes(x = coef.name, y = mean.median, color = model)) +

  geom_pointrange(aes(ymin = low, ymax = upper),
    position = position_dodge(width = 0.8)) +
 labs(y = "Effect", x = "") +
 coord_flip() +
 ggtitle("Fixed effects estimates from the main model") +
 scale_color_manual(values = c("blue", "orange", "forestgreen"))
 
 
Cheers,
 
Josh
 


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2



--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles

plot.png
Reply all
Reply to author
Forward
0 new messages