I can't get R Studio to recognize any pipes or get this following code working to make a graph.

linear regression of concentration by year.") +

  • theme_classic() +
  • scale_color_manual(labels=c("CH4 (ppb)", "CO2 (ppm)", "N20 (ppb)"),
  •                  values=c("Red", "Black", "Blue"))
    

Error in greenhouse_gases %>% ggplot(aes(x = year, y = Concentration, :
could not find function "%>%"

greenhouse_gases %/%

  • ggplot(aes(x = year, y = Concentration, color = gas)) +
  • geom_point() +
  • geom_smooth(method = lm) +
  • labs(x="Year",
  •    y="Gas Concentration",
    
  •    color="Gas(Unit)",
    
  •    caption = "Concentration of greenhouse gases by year. Line is linear regression of concentration by year.") +
    
  • theme_classic() +
  • scale_color_manual(labels=c("CH4 (ppb)", "CO2 (ppm)", "N20 (ppb)"),
  •                  values=c("Red", "Black", "Blue"))
    

Error in fortify():
! data must be a <data.frame>, or an object
coercible by fortify(), or a valid <data.frame>-like
object coercible by as.data.frame(), not a
object.
:information_source: Did you accidentally pass aes() to the data
argument?
Backtrace:

  1. ggplot2::ggplot(aes(x = year, y = Concentration, color = gas))
  2. ggplot2:::ggplot.default(aes(x = year, y = Concentration, color = gas))
  3. ggplot2:::fortify.default(data, ...)

So, in order to help you, I need to know the structure of your data, so could you create some dummy data in the same structure of your actual data? Also please send the whole code not as a picture but in text so I'm able to copy it and run it by myself. Best send it in the following format:
´´´r
your code

´´´

library(dslabs)

greenhouse_gases %>% 
  ggplot(aes(x = year, y = Concentration, color = gas)) +
  geom_point() +
  geom_smooth(method = lm) +
  labs(x="Year",
       y="Gas Concentration",
       color="Gas(Unit)",
       caption = "Concentration of greenhouse gases by year. Line is linear regression of concentration by year.") +
  theme_classic() +
  scale_color_manual(labels=c("CH4 (ppb)", "CO2 (ppm)", "N20 (ppb)"),
                     values=c("Red", "Black", "Blue"))

Thank you! Should this be acceptable?

Your code seems to show that you are trying to load a library outside an R chunk. This does not work.

Try something like

```{r}
library(tidyverse)
library(dslabs)
```


before the rest of your code.

I tried it as following:

library(dslabs)
library(tidyverse)

greenhouse_gases <- data.frame(year=c(2013,2013,2013,2014,2014,2014,2015,2015,2015),gas=factor(c("CH4 (ppb)", "CO2 (ppm)", "N20 (ppb)", "CH4 (ppb)", "CO2 (ppm)", "N20 (ppb)","CH4 (ppb)", "CO2 (ppm)", "N20 (ppb)")),Concentration=c(3,4,3,5,6,4,3,7,8))

greenhouse_gases %>% 
  ggplot(aes(x = year, y = Concentration, color = gas)) +
  geom_point() +
  geom_smooth(method = lm) +
  labs(x="Year",
       y="Gas Concentration",
       color="Gas(Unit)",
       caption = "Concentration of greenhouse gases by year. Line is linear regression of concentration by year.") +
  theme_classic() +
  scale_color_manual(labels=c("CH4 (ppb)", "CO2 (ppm)", "N20 (ppb)"),
                     values=c("Red", "Black", "Blue"))

This was the result:

Do you want to create something like this, @gamingunicorndude ?

If that's the case, the code for the plot is perfectly fine. So I would assume, there is a problem with your data format. It has to be in long format, "Concentration" and "year" have to be numeric and "gas" has to be a factor. Also all the packages, that are needed have to be installed (in this case the packages "tidyr" and "ggplot2" but you can also install "tidyverse") and then activated for the current session by the library-argument.
If you need further help or don't understand my answer, please ask :slight_smile: