I was building a scatterplot to correlate the abundance of certain organisms with Temperature. While building the graph I realized that the x axis values do not appear.
This is an example of how my dataset looks like:
> dput(head(abundance))
structure(list(OGA_ID = c(20L, 22L, 66L, 75L, 91L), sample_ID = structure(c(5L,
1L, 2L, 3L, 4L), .Label = c("TARA_N010000218", "TARA_N010000238",
"TARA_N010000911", "TARA_N010000955", "TARA_N010000980"), class = "factor"),
vlookup = c(2.6820250147109e-06, 4.2504952889635e-07, 3.098736273373e-07,
4.7282955865616e-07, 6.4437058525603e-07), relative.abundance = c(2.6820250147109e-06,
4.2504952889635e-07, 3.098736273373e-07, 4.7282955865616e-07,
6.4437058525603e-07), log = c(-5.57153717588776, -6.37156046083652,
-6.50881538403584, -6.32529538161919, -6.19086429282228),
station = structure(c(3L, 2L, 2L, 1L, 3L), .Label = c("TARA_188",
"TARA_205", "TARA_210"), class = "factor"), depth = structure(c(2L,
3L, 2L, 1L, 2L), .Label = c("DCM", "MES", "SRF"), class = "factor"),
size.fraction = structure(c(2L, 2L, 2L, 2L, 1L), .Label = c("[>0.8µm]",
"[0.8-20µm]"), class = "factor"), temperature = c(61.5754,
72.4693, 72.4456, 78.3555, 61.5754)), row.names = c(NA, 5L
), class = "data.frame")
This is my code:
{r, fig.width=10, fig.height=5}
library(ggplot2)
abundance_environment <- read.table('/home/agalvez/data/environmental_data/vanellid/environmental_parameters.csv', sep="\t", header=TRUE)
lineplot <- ggplot(abundance_environment, aes( x = abundance_environment$temperature...C., y = abundance_environment$log, group = abundance_environment$Depth_Nominal , colour = abundance_environment$Depth_Nominal))
geom_point( size =2, shape =16)
xlab("Temperature(ºC)") ylab("Relative abundance") ggtitle("Abundance-Temperature")
theme_minimal()
labs(colour = "Depth")
lineplot
I do not see why the axis are hidden. Could someone help me with that?
Thanks in advance!
CodePudding user response:
I see a few issues here.
- When you call your variables to map them in
ggplot(aes())
, you should use just the unquoted variable name (e.g.ggplot(data = mtcars, aes(x = disp))
rather thanggplot(data = mtcars, aes(x = mtcars$disp))
- The variable names in the data you shared don't match what's in your ggplot call. E.g. you are calling
x = abundance_environment$temperature...C.
but the variable in the data you shared is calledtemperature
. This lead me to wonder if you're accidentally plotting another version of the data that's in your environment. Perhaps just try clearing your environment and re-loading the data and plot. - When I plot your data snippet after fixing the above issues, the plot looks as I would expect with
x
axis values. If you are also getting this result, please clarify what you want it to look like.
library(tidyverse)
d <- structure(list(temperature = c(61.5754, 72.4693, 72.4456, 78.3555, 61.5754), log = c(-5.57153717588776, -6.37156046083652, -6.50881538403584, -6.32529538161919, -6.19086429282228), depth = structure(c(2L, 3L, 2L, 1L, 2L), levels = c("DCM", "MES", "SRF"), class = "factor")), row.names = c(NA, 5L), class = "data.frame")
d %>%
ggplot(aes(x = temperature, y = log, colour = depth))
geom_point(size =2, shape =16)
xlab("Temperature(ºC)")
ylab("Relative abundance")
ggtitle("Abundance-Temperature")
theme_minimal()
labs(colour = "Depth")
Created on 2022-09-23 by the reprex package (v2.0.1)
CodePudding user response:
the issue with my code was that I was specifying the dimensions of the plot and this was hiding the x axis.
So I solved it by changing {r, fig.width=10, fig.height=5} by simply {r}.
Thank you a lot for yuour help.