1

CODE:

Lef4 <- read.csv2("Lef4 expression.csv")

head(Lef4_expression)

Lef4graph <- ggplot(Lef4_expression,aes(x = Hour, y = Copies.Lef4.ng)) + 
  geom_dotplot(binaxis = 'y', stackdir = 'center')
Lef4graph

I am trying to make a simple dotplot from a csv file I have. I can get y axis values to appear but all x axis value are the same value. Please help!

Graph generated:

enter image description here

Data being entered:

enter image description here

Trying to create a dotplot and all x axis values are the same despite .csv having multiple values to graph on x axis. I have tried searching online to find a solution but everything doesnt seem to work. I am new to ggplot and R so it could be an easy solution.

stefan
  • 90,330
  • 6
  • 25
  • 51
  • 3
    Could you please share some reproducible data using `dput`? So we can help you better. – Quinten Nov 01 '22 at 16:39
  • 3
    Welcome to SO! It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Please do not post an image of code/data/errors [for these reasons](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557). Just include the code, console output, or data (e.g., dput(head(x)) or data.frame(...)) directly. – stefan Nov 01 '22 at 16:46
  • 2
    I think you should use `geom_point()` instead of `geom_dotplot`. – MarBlo Nov 01 '22 at 17:27
  • Thank you MarBlo! This seems to have fixed it. Could you explain the rational behind this? – Nicholas Furlong Nov 01 '22 at 19:28

1 Answers1

0

As you asked for the rational for using geom_point instead of geom_dotplot: What geom_dotplot does is creating bins - in your case along the y-axis (your variable Copies.Left4.ng ) and count the number of occurrences in those bins. Each occurrence is represented by one point. geom_dotplot puts these numbers/bins then somewhere on the x-axis which you have chosen.

A good case for using geom_dotplot in my opinion is when you have to count occurences for categorical data like in this example:

library(ggplot2)

ggplot(ToothGrowth, aes(x=factor(dose), y=len)) + 
  geom_dotplot(binaxis='y', stackdir='center')

As you can see, I have made the dose-data a factor in the aesthetics. This will make the ticks on the x-axis equidistant. This is OK for this dataset.

But your dataset is non-categorical for Hour and for Copies (I have chosen this a variable name.) I have taken a little simplified data frame than yours and defined it in read.table. This is then followed by making the plot with geom_point.

df <- read.table(text = "
  Hour  Copies
  46.0  8807
  72    6781
  72    4311
  29.5  3313
  42    3096
  29.5  2807
  42    2141
  24    37
  0     31
  24    24
  -24   17
", header = TRUE)

library(ggplot2)

ggplot(df, aes(x=Hour, y=Copies)) + geom_point()

You may find further useful information in R-Graphics Cookbook.

MarBlo
  • 4,195
  • 1
  • 13
  • 27