0

I have neuroscientific data where we count synapses/cells in the cochlea and quantify these per frequency. We do this for animals of different ages. What I thus ideally want is the frequencies (5,10,20,30,40) in the x-axis and the amount of synapses/cells plotted on the y-axis (usually a numerical value from 10 - 20). The graph then will contain 5 lines of the different ages (6 weeks, 17 weeks, 43 weeks, 69 weeks and 96 weeks).

I try this with ggplot and first just want to plot one age. When I use the following command:

ggplot(mydata, aes(x=Frequency, y=puncta6)) + geom_line()

I get a graph, but no line and the following error: 'geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?'

So I found I have to adjust the code to:

ggplot(mydata, aes(x=Frequency, y=puncta6, group = 1)) + geom_line()

This works, except for the fact that my first data point (5 kHz) is now plotted behind my last data point (40 kHz)......... (This also happens without the 'group = 1' addition). How do I solve this or is there an easier way to plot this kind of data?

I couldnt add a file so I added a photo of my code + graph with the 5 kHz data point oddly located and I added a photo of my data in excel.

example data example data

example code and graph example code and graph

stefan
  • 90,330
  • 6
  • 25
  • 51
  • 1
    Please do not post code and data as images, per [these reasons](https://meta.stackoverflow.com/a/285557/11374827). – teunbrand Jan 11 '21 at 21:17
  • Instead provide the data you are using by adding the output of `dput(mydata)` into your question and also pasting the code you are using as text so others can test and improve it. – Dan Adams Jan 11 '21 at 22:31
  • The issue is that your `Frequency` column is a character. Therefore the categories get ordered alphabetically. You could prevent that by converting to a factor and setting the levels in the desired order e.g. `mydata$Frequency <- factor(mydata$Frequency, levels = c("5 kHz", "10 kHz", ...))` or you remove the kHz and convert to a numeric using e.g. `as.numeric(gsub("kHz", "", mydata$Frequency))`. – stefan Jan 11 '21 at 22:49
  • 1
    See this on reproducible examples: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – william3031 Jan 11 '21 at 22:52

0 Answers0