Plot negative values with ggplot2

ggplot2

#1

Hi there!
I would like to use the ggplots2 package to a dot plot and plot some phenotype data vs. the latitude coordination (it’s the place the where the sample was collected). The dots should be dependent of the size of the phenotype. And there’s the problem I failed so far: I have for the phenotype negative and positive values. Do you know if there is a possibility to plot these data where for example -10 and +10 have them same size and values in between have an intermediate sizes?

Thanks a lot for your ideas.


#2

I don’t have any idea about the data structure you have problems with in particular, however I think I get the gist enough to help with a solution.

What you need is a transformation of the value in question, that maps the the positive values and the negative values to the same values, hopefully in a way that preserves size (that is; symmetric and monotonically increasing on the interval [0,+∞)). This can be done simply by using the abs function.

Where you can choose to do the transformation inside the aes

library(tidyverse)
tibble(value = runif(n = 20, min = -10, 10),
       lat = 1:20) %>%
  ggplot(aes(lat, value, size = abs(value))) +
  geom_point()

or modify the data.frame you are working with

tibble(value = runif(n = 20, min = -10, 10),
       lat = 1:20) %>%
  mutate(size = abs(value)) %>%
  ggplot(aes(lat, value, size = size)) +
  geom_point()

#3

How about creating a new variable equal to the absolute value of your phenotype value and then using that new column for the size aesthetic.

You might need to take abs(phenotype) + , to prevent a phenotype near +/- 0 from being plotted too small.