r - ggplot2 scatterplot and labels -
i attempting produce scatter plot using ggplot2 library. data frame (called scatterplotdata) in form:
115 2.3 120 1.6 . . . 132 4.3
(the ... signifies many other similar values). essentially, 2 column data frame. have labels go along each of points. firstly, i'm having trouble scatterplot itself. i'm using following code:
p <- ggplot(scatterplotdata, aes("distance (bp)", "intensity")) p + geom_point()
however, using above code, following plot:
obviously, it's not scatter plot. so, i'd helpful if point out i'm doing wrong.
secondly, it's labels. have many datapoints have risk of overlapping datapoints. how should go putting on labels each point using ggplot? also, states use directlabels package overlap free labelled scatterplot using different colors, however, i'm not sure how go ggplot
haven't found documentations regarding use of directlabels ggplot
.
any either (or both) question(s) appreciated - thanks.
first, more helpful if provided reproducible example precisely described data.
you should not passing variable names in aes
in quotes. i'm not sure got from, there wouldn't single example of doing that can think of (unless using aes_string
case).
however, appears have awkward variable name, i.e. distance (bp)
. non-standard , not recommended. names should not have spaces in them. best thing rename column sensible , like:
p <- ggplot(scatterplotdata, aes(x = distance_bp,y = intensity)) p + geom_point()
if not rename column, might work:
p <- ggplot(scatterplotdata, aes(x = `distance (bp)`,y = intensity)) p + geom_point()
note backticks, not single quotes.
Comments
Post a Comment