i'm trying create plot errorbars following data (dput of dataframe in end). i'd create errorbars "est a" , "est b" variables each "loc", cannot figure out right way melt/cast data each "loc" have 2 rows several columns.
i.e. i'd convert dataframe into
loc est value lb ub
a 0.56 0.26 1.20
a b 0.26 0.11 0.60
b 0.13
b b 0.03
c a
c b
ggplot(test,aes(x=loc,y=value,color=est))+geom_point()+geom_errorbar(aes(ymax=ub,ymin=lb)) > dput(test) structure(list(loc = c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s"), `est a` = c(0.563270934055709, 0.137109873453407, 0.0946514679398302, 0.185103062070327, 0.0322566231880829, 0.122509922923046, 0.120243043198876, 0.496530499385046, 0.469200921538171, 0.0605252215342125, 0.102364314964088, 0.115500654388976, 0.226320301860998, 0.553299923910439, 0.0284461712437990, 0.161231809656951, 0.129270683014873, 0.0691902563736868, 4.22775563209408e-10), `est b` = c(0.261222076585074, 0.0361169058045732, 0.0389295009573361, 0.0341489915400374, 0.00722206105211422, 0.0756192543690879, 0.0638910584951127, 0.112923798991901, 0.169215410079679, 0.0235142527703486, 0.0347964005083873, 0.0485649792804626, 0.057534910753763, 0.142573116854277, 0.0221769276223588, 0.104198059736499, 0.0234801538140553, 0.072563099770018, 1.93211916678252e-10), `a lb` = c(0.262976608413878, 0.0724138165552355, 0.0496821188642757, 0.083935851825787, 0.00630380846921399, 0.0490562081838664, 0.0467393615329014, 0.20284436584412, 0.178474018619480, 0.0171506568665928, 0.0503363150211533, 0.0600281091658352, 0.0747597162489745, 0.276929613768523, 0.00665167561787145, 0.0580348444006193, 0.0516432163190537, 0.0228220757228112, 0), `a ub` = c(1.20647287629726, 0.259606775235633, 0.180324442434493, 0.408206300913301, 0.165057321233572, 0.305948661143090, 0.309340756132258, 1.21542708762748, 1.23351010121895, 0.213595459944227, 0.208168853315217, 0.222235904972905, 0.685140094216929, 1.10548237017075, 0.121651250740107, 0.447932560408103, 0.323583825296458, 0.209765826526966, inf), `b lb` = c(0.111866193520147, 0.0169169666997800, 0.0186761266424921, 0.0121471488870159, 0.00126380823047679, 0.0279532804037691, 0.0225442254744942, 0.0369377660459994, 0.0509571176650792, 0.00592607390737984, 0.0157043256006381, 0.0231925392578512, 0.0153998561264800, 0.0612241780775462, 0.00507024995333768, 0.0364091610491575, 0.00745586930827693, 0.0243798413908829, 0), `b ub` = c(0.609987442570209, 0.0771078472899858, 0.0811466999446844, 0.0960022499146318, 0.0412706331409062, 0.204565315724654, 0.181069310198491, 0.345223486522794, 0.561920617187038, 0.0933029341161755, 0.0770991075408484, 0.101694652159027, 0.214954342966326, 0.332010886676128, 0.0970003694676995, 0.298200654450461, 0.0739441103828987, 0.215973654783605, inf)), .names = c("loc", "est a", "est b", "a lb", "a ub", "b lb", "b ub"), row.names = c(na, -19l), class = "data.frame")
i called dataframe data, then:
test <- with(data, data.frame( loc = rep(loc,2), est = rep(c("a","b"),each=nrow(data)), value = c(get("est a"),get("est b")), lb = c(get("a lb"),get("b lb")), ub = c(get("a ub"),get("b ub")) ) ) ggplot(test,aes(x=loc,y=value,color=est))+geom_point()+ geom_errorbar(aes(ymax=ub,ymin=lb))
and please, never ever use variable names space if possible. if didn't, have done:
test <- with(data, data.frame( loc = rep(loc,2), est = rep(c("a","b"),each=nrow(data)), value = c(esta,estb), lb = c(alb,blb), ub = c(aub,bub) ) ) ggplot(test,aes(x=loc,y=value,color=est))+geom_point()+ geom_errorbar(aes(ymax=ub,ymin=lb))
Comments
Post a Comment