1

I am using the package growthcurver to create a graph with a sigmoidal curve. It needs to have a logarithmic scale on the y axis.

This works to create a graph without a log scale:

# install.packages("growthcurver")
library("growthcurver")
gcfit <- SummarizeGrowth(curveA$time, curveA$biomass)
gcfit
plot(gcfit)

I have tried plot(gcfit, log=y) and plot(gcfit, log="curveA$biomass"). This gives me the error

'Non-numeric argument to mathematical function'.

Could it be that I am using a data frame? How do I get around this?

my data

dput(curveA)

structure(list(time = c(1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 
21, 22, 23, 24, 25), biomass = c(0.153333333, 1.303333333, 2.836666667, 
4.6, 6.21, 6.746666667, 7.283333333, 7.973333333, 8.663333333, 
9.046666667, 10.19666667, 10.50333333, 11.04, 11.88333333, 11.96, 
11.96, 9.966666667)), class = c("spec_tbl_df", "tbl_df", "tbl", 
"data.frame"), row.names = c(NA, -17L), spec = structure(list(
cols = list(time = structure(list(), class = c("collector_number", 
"collector")), biomass = structure(list(), class = c("collector_number", 
"collector"))), default = structure(list(), class = c("collector_guess", 
"collector")), skip = 1), class = "col_spec"))
rawr
  • 20,481
  • 4
  • 44
  • 78
  • @Dave2e That was my thought as well, but it seems [`plot.gcfit`](https://rdrr.io/cran/growthcurver/src/R/helpers.R#sym-plot.gcfit) does not accept `log = "y"`. – Maurits Evers Mar 16 '20 at 00:01

1 Answers1

0

Without the data that you are using it is difficult to reproduce the problem (how to produce reproducible example: How to make a great R reproducible example), but the easiest solution to your problem might be using log function directly on the data...

gcfit_log <- SummarizeGrowth(curveA$time, log10(curveA$biomass))
plot(gcfit_log)

The workaround is to extract the data from the model and plot using ggplot2 package:

library(ggplot2)
library(dplyr)

gcfit <- SummarizeGrowth(curveA$time, curveA$biomass)

points_data <- bind_cols(t = gcfit$data$t, n = gcfit$data$N)
line_fit <- bind_cols(x = max(gcfit$data$t) * (1 : 30) / 30, 
                      y = NAtT(gcfit$vals$k, gcfit$vals$n0, gcfit$vals$r, 
                               max(gcfit$data$t) * (1 : 30) / 30))

ggplot(data = points_data, aes(t, n + 1)) +
  geom_point() +
  geom_line() +
  geom_line(data = line_fit, aes(x, y + 1), color = "red") +
  scale_y_log10()
knytt
  • 583
  • 5
  • 15
  • Thank you for your help, I have added my data so hopefully that makes things a bit clearer. Do you know a better way I can log the axis if that is the issue? Sorry, I am new to code :) – stephanie Mar 15 '20 at 23:41
  • Can you provide your data as an output from ```dput(curveA)``` function? The picture does not really help. – knytt Mar 15 '20 at 23:44
  • I have added it – stephanie Mar 15 '20 at 23:50
  • I added a workaround to plotting the data and the model. Notice that in order not to get -Inf/Inf after the log transform, the y values get +1 – knytt Mar 16 '20 at 01:01