Search code examples
rggplot2geom

I am drawing a plot in ggplot in R and all I am getting as the result is a line with points in vertical direction with no x-labels or markings


ggplot(data=df, aes(x='Matcing_Probability', y=Locus_Name, group=1)) + 
+     geom_line(color="#aa0022", size=1.75) + 
+     geom_point(color="#aa0022", size=3.5) 

enter image description here

This is the graph I am getting from the code.


Solution

  • You need to send ggplot2 symbols (unquoted column names) in aes() if you are assigning an aesthetic to a column in your dataset. Otherwise, it will assume you are sending the string of a new symbol. So:

    # your original
    ggplot(data=df, aes(x='Matching_Probability', y=Locus_Name, group=1))
    
    # change to this:
    ggplot(data=df, aes(x=Matching_Probability, y=Locus_Name, group=1))
    

    Consider the difference in the following example to highlight why even more:

    # this works fine
    df <- data.frame(x=1:10, y=1:10)
    ggplot(df, aes(x=x,y=y)) + geom_point()
    

    enter image description here

    # this doesn't:
    ggplot(df, aes(x="x",y=y)) + geom_point()
    

    enter image description here