GGplot graph: problem with the x-axis values: appearing in the wrong place on the graph

Hello all,

I am trying to produce a GGPLOT with the following command:

ggplot(Errortrial, aes(x = Target, y = Absolutefirststoperror, color = as.character(Type), shape = as.character(Type))) + geom_point(shape=16)+ geom_point(data=Errortrialoriginal,shape=19,size = 4,mapping=aes(x=Target, y=Absolutefirststoperror)) + geom_line(data=Errortrialoriginal,aes(group=Type),size=2) + geom_errorbar(data=Errortrialoriginal,mapping=aes(x=Target, ymin=Absolutefirststoperror-SE,ymax=Absolutefirststoperror+SE),size=0.5) + theme_bw() + guides(color = guide_legend("Trial-to-trial variability in gain (SD)"), shape = guide_legend("Trial-to-trial variability in gain (SD)")) + labs(x = "Target distance (m)", y = "Absolute error in stop location (m)") + theme(axis.title.x = element_text(size=14, face="bold",margin=margin(t=0,r=0,l=0,b=20),hjust=0.5,vjust=-2.5), axis.title.y = element_text(size=14, face="bold",vjust=5,margin=margin(t=0,r=0,l=20,b=0)),legend.text=element_text(size=14),title=element_text(size=14,face="bold"), plot.title = element_text(hjust = 0.5), legend.title = element_text(size=14,face="bold"), axis.text.x=element_text(size=14),axis.text.y=element_text(size=14), panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + scale_colour_brewer(palette="Dark2")

However, my graph is appearing like this:

enter image description here

Would anybody be so kind as to suggest why this might be?

Here is the data...

structure(list(Target = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("70.1075", 
"101.71", "149.1155", "220.2225", "326.8835"), class = "factor"), 
    Type = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L), .Label = c("Beaconed-0", 
    "Beaconed-0.5", "Beaconed-2", "Probe-0", "Probe-0.5", "Probe-2"
    ), class = "factor"), ID = c("P_200214103155", "P_200214123342", 
    "P_200217101213", "P_200219091823", "P_200219102411", "P_200219111605", 
    "P_200219123120", "P_200219163622", "P_200219175102", "P_200220130332", 
    "P_200220145557", "P_200221101028", "P_200224092247", "P_200225171612", 
    "P_200225184226", "P_200214103155", "P_200214123342", "P_200217101213", 
    "P_200219091823", "P_200219102411", "P_200219111605", "P_200219123120", 
    "P_200219163622", "P_200219175102", "P_200220130332", "P_200220145557", 
    "P_200221101028", "P_200224092247", "P_200225171612", "P_200225184226", 
    "P_200214103155", "P_200214123342", "P_200217101213", "P_200219091823", 
    "P_200219102411", "P_200219111605", "P_200219123120", "P_200219163622", 
    "P_200219175102", "P_200220130332", "P_200220145557", "P_200221101028", 
    "P_200224092247", "P_200225171612", "P_200225184226", "P_200214103155", 
    "P_200214123342", "P_200217101213", "P_200219091823", "P_200219102411"
    ), Absolutefirststoperror = c(5.8022, 8.6136, 7.7334, 3.3824, 
    4.1562, 8.3978, 6.7964, 5.8266, 5.0725, 4.153, 5.977, 4.5832, 
    7.57525, 4.66425, 7.55, 6.7488, 7.8048, 7.5708, 7.2012, 4.3314, 
    8.2928, 5.1, 3.0236, 4.7482, 5.1454, 3.8708, 5.6708, 6.7938, 
    4.4986, 6.9404, 5.7226, 6.5688, 6.9756, 4.3906, 13.908, 13.6114, 
    4.8192, 4.7482, 3.2736, 2.5638, 6.602, 3.7658, 9.3858, 8.9644, 
    8.5324, 14.7138, 10.7642, 9.6718, 16.383, 5.9138), transform = c(1.75823715597722, 
    2.15334234951937, 2.04554861065665, 1.21858551669378, 1.42460119527448, 
    2.12796976678432, 1.91639306022947, 1.76243363984623, 1.62383379271783, 
    1.42383096464862, 1.78791876984212, 1.52239744411223, 2.02488635415117, 
    1.53992704966997, 2.02154756326093, 1.90936471130232, 2.05473892903946, 
    2.02429874218263, 1.97424767880133, 1.46589081539103, 2.1153876684533, 
    1.62924053973028, 1.10644817443588, 1.55776559885943, 1.63810311164787, 
    1.35346120402465, 1.73533020126134, 1.91601043156591, 1.50376623726006, 
    1.93735940974538, 1.74442324757176, 1.88233116741244, 1.94241834551317, 
    1.47946589200769, 2.63246421414561, 2.61090767691312, 1.57260793918338, 
    1.55776559885943, 1.18589029677517, 0.941490532895897, 1.887372633431, 
    1.32596032208019, 2.23919790881364, 2.1932611778793, 2.14387068183553, 
    2.68878582892075, 2.37622581314541, 2.26921443485221, 2.79624421183813, 
    1.7772886027996), transform2 = c(2.40877562259335, 2.9348935244741, 
    2.78089913517193, 1.83913022921162, 2.03867604096384, 2.89789578832642, 
    2.60699060220784, 2.41383512278697, 2.25222112591104, 2.03789106676486, 
    2.44479037956222, 2.14084095625995, 2.75231720555607, 2.15968747739112, 
    2.74772633280682, 2.59784526098072, 2.79370721443748, 2.75150867707154, 
    2.68350517048132, 2.08120157601324, 2.87972220882501, 2.25831795812724, 
    1.73885019481265, 2.17903648432054, 2.26834741607189, 1.96743487821071, 
    2.38134415824341, 2.60649189524924, 2.12099033472574, 2.6344638923318, 
    2.39219564417294, 2.5629670306112, 2.64113611917296, 2.09537586127167, 
    3.72934310569569, 3.68936308866449, 2.19526763744196, 2.17903648432054, 
    1.80930926046378, 1.60118705965293, 2.56943573572098, 1.94056692747248, 
    3.06362530345994, 2.99406078762606, 2.92102721657981, 3.83585714019696, 
    3.28088402720974, 3.10995176811474, 4.0475918766595, 2.43183058620456
    )), row.names = c(NA, -50L), class = "data.frame")

What does Errortrial look like? Why are all the values on the left hand side? A reproducible example would be useful:

This shows that distance values appear as strings, rather than numbers, so a first step would be to make sure you import the column data as numbers. Or, the function parse_double() might help after importing.

1 Like

@dromano thanks so much, that works!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.