Reputation: 197
enter image description here I'm using this script to try to creat a figure like this I'm using the data and script bellow, but the following message has appeared:
Error: Aesthetics must be either length 1 or the same as the data (11): x, y, ymin, ymax
The output of dput(graf1)is:
structure(list(est = structure(c(10L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 11L), .Label = c("A", "B", "C", "D", "E ", "F", "G",
"H", "I ", "Intercept ", "J"), class = "factor"), min = c(-2.59987657,
1.90207329, 0.19540912, 0.38539491, 0.44573408, -0.62036798,
-0.25411668, 0.12885761, -1.11518838, -0.08929551, -0.07907754
), max = c(-2.12964144, 2.31358683, 0.34741113, 0.53284866, 0.6833492,
-0.32613644, 0.12285579, 0.46712478, -0.48094942, 0.05204147,
0.06417294)), .Names = c("est", "min", "max"), class = "data.frame", row.names = c(NA,
-11L))
script
graf1 <- read.csv(file="tab.csv", header = TRUE, sep = ";")
str(graf1)
attach(graf1)
names(graf1)
dput(graf1)
library(ggplot2)
ggplot(graf1, aes(x=graf1$X, y=graf1$est, ymin=graf1$min,ymax=graf1$max))+
geom_pointrange()+
geom_point()+
coord_flip()+geom_hline(yintercept = 0, linetype="dotted")+
xlab('Variable')
est min max
Intercept -2.59987657 -2.12964144
A 1.90207329 2.31358683
B 0.19540912 0.34741113
C 0.38539491 0.53284866
D 0.44573408 0.6833492
E -0.62036798 -0.32613644
F -0.25411668 0.12285579
G 0.12885761 0.46712478
H -1.11518838 -0.48094942
I -0.08929551 0.05204147
J -0.07907754 0.06417294
Upvotes: 1
Views: 509
Reputation: 43334
Since there are only min and max values, about the best you can do is geom_linerange
:
library(ggplot2)
df <- data.frame(est = c("Intercept", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"),
min = c(-2.59987657, 1.90207329, 0.19540912, 0.38539491, 0.44573408, -0.62036798, -0.25411668, 0.12885761, -1.11518838, -0.08929551, -0.07907754),
max = c(-2.12964144, 2.31358683, 0.34741113, 0.53284866, 0.6833492, -0.32613644, 0.12285579, 0.46712478, -0.48094942, 0.05204147, 0.06417294))
ggplot(df, aes(factor(est, levels = rev(est)), ymin = min, ymax = max)) +
geom_linerange() +
geom_hline(yintercept = 0, linetype = "dotted") +
coord_flip() +
labs(x = 'Variable')
Upvotes: 1