Error in interaction(Habitat, year) : object 'year' not found
Please help im new to Rstudio and using it and i cant work this out, its driving me mad! Thx
Im gonna be honest here, i dont know what any of that is, however, i believe my code is short and snappy? If you would still take a look at it in 'untidy format' will u please let me know? This is my problem, its the group_by() that seems to be the issue as it doesnt recognise one of my objects? Here is the code:
##Bar chart with Year
data <- read.csv("Giraffe_Data.csv", stringsAsFactors = FALSE)
Giraffes_summary2 <- filter(data, Habitat %in% c("Hill_slope", "Plateau")) %>%
group_by( Habitat, Year)
Giraffes_summary2 <- summarise(Giraffes_summary2, mean_Giraffe = mean(Herd_size),
sd_Giraffe = sd(Herd_size),
se_Giraffe = sd(Herd_size)/sqrt(n()))
ggplot(data = Giraffes_summary2,
mapping = aes(x = interaction(Habitat, Year), y = mean_Giraffe, fill = Habitat)) +
geom_col() +
geom_errorbar(aes(ymin = mean_Giraffe - sd_Giraffe,
ymax = mean_Giraffe + sd_Giraffe), width = 0.3)
It works for me.
#data <- read.csv("Giraffe_Data.csv", stringsAsFactors = FALSE)
library(dplyr)
library(ggplot2)
Giraffes_summary2 <- filter(data, Habitat %in% c("Hill_slope", "Plateau")) %>%
group_by( Habitat, Year)
Giraffes_summary2 <- summarise(Giraffes_summary2, mean_Giraffe = mean(Herd_size),
sd_Giraffe = sd(Herd_size),
se_Giraffe = sd(Herd_size)/sqrt(n()))
#> `summarise()` regrouping output by 'Habitat' (override with `.groups` argument)
ggplot(data = Giraffes_summary2,
mapping = aes(x = interaction(Habitat, Year), y = mean_Giraffe, fill = Habitat)) +
geom_col() +
geom_errorbar(aes(ymin = mean_Giraffe - sd_Giraffe,
ymax = mean_Giraffe + sd_Giraffe), width = 0.3)
Created on 2020-07-08 by the reprex package (v0.3.0)
It seems to work for other people but not for me!!?
Any idea what this issue could be?
Error in interaction(Habitat, year) : object 'year' not found
Is year supposed to be Year?
Or are you getting some other error now?
I tried that but it still created an error?
Tried what? What error?
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.