Reputation: 225
I have a data frame that looks like this:
head(all)
basisOfProxy method citation season low high season.method.basis
beetle CRACLE Fletcher et al 2019b Tmin -23.50 -20.40 Tmin_CRACLE_beetle
beetle CRACLE-CA Fletcher et al 2019b Tmin -25.00 -10.40 Tmin_CRACLE-CA_beetle
plant CRACLE Fletcher et al 2017 Tmin -12.18 -11.51 Tmin_CRACLE_plant
plant CRACLE-CA Fletcher et al 2017 Tmin -21.70 -8.10 Tmin_CRACLE-CA_plant
plant cRacle Unpublished Tmin -13.48 -10.53 Tmin_cRacle_plant
plant Unweighted MCR Unpublished Tmin -28.50 -3.16 Tmin_Unweighted MCR_plant
str(all)
'data.frame': 39 obs. of 7 variables:
$ basisOfProxy : chr "beetle" "beetle" "plant" "plant" ...
$ method : chr "CRACLE" "CRACLE-CA" "CRACLE" "CRACLE-CA" ...
$ citation : chr "Fletcher et al 2019b" "Fletcher et al 2019b" "Fletcher et al 2017" "Fletcher et al 2017" ...
$ season : chr "Tmin" "Tmin" "Tmin" "Tmin" ...
$ low : num -23.5 -25 -12.2 -21.7 -13.5 ...
$ high : num -20.4 -10.4 -11.5 -8.1 -10.5 ...
$ season.method.basis: chr [1:39, 1] "Tmin_CRACLE_beetle" "Tmin_CRACLE-CA_beetle" "Tmin_CRACLE_plant" "Tmin_CRACLE-CA_plant" ...
I am trying to make a plot using geom_linerange and ggplot to make a plot that is a box or thick line of the range (low to high) on the Y axis, with season.method.basis as the labels for each data point, something like this example in terms of the orientation and what I am communicating, but looking more like this example in terms ofjust having a solid bar representing the range.
I have tried a few different methods based on examples I have found here on stackexchange, for example:
Example 1
ggplot() +
geom_linerange(data = all, aes(x = season.method.basis, ymin = low,
ymax = high, lwd = 1, color = season)) +
scale_y_continuous(c(-30, 30))
#Example 2
ggplot(all) +
geom_linerange(aes(x= season.method.basis, ymin=low, ymax=high, lwd=1, colour=season))
#eExample 3
ggplot(all, aes(x = season.method.basis)) +
geom_linerange(aes(ymin=low,ymax=high), linetype=2,color="blue")
I also saw that in the example in ?ggplot x was a factor. Whether what looked like text was factors in other examples I could not tell, so I tried converting season.method.basis to factors and tried that.
all$fsmb <- factor(all$season.method.basis)
Example 1
ggplot() +
geom_linerange(data = all, aes(x = fsmb, ymin = low,
ymax = high, lwd = 1, color = season)) +
scale_y_continuous(c(-30, 30))
#Example 2
ggplot(all) +
geom_linerange(aes(x= fsmb, ymin=low, ymax=high, lwd=1, colour=season))
#eExample 3
ggplot(all, aes(x = fsmb)) +
geom_linerange(aes(ymin=low,ymax=high), linetype=2,color="blue")
Every variant still results in the same error.
Seemingly similar examples include this but they specified y= xmin= and xmax=, which were then being ingnore with x, ymin, and ymax not specified, whereas I have (tried to?) specify x , ymin and ymax.
This one is the same error, but I have them concatenated, so the solution doesn't seem to apply here.
Here they did not specify the x at all, whereas I believe I have it in the same position as recommended in the answer in at least some of the examples.
I assume I have missed something simple, but I am stumped.
Upvotes: 0
Views: 1866
Reputation: 225
This error appears to be caused by a clash with other libraries. I do not know which library. To solve the error I unloaded all libraries, restarted R, and loaded only ggplot2. On running the code I pointed to in the comment above, it now produced the same result as the OP of that question. I tried rerunning the code I have above, and I now get (awful!) plots and no error.
Upvotes: 0