Error code in Scatter Plots for Exploratory Analysis

, ,

Screen Link: https://app.dataquest.io/m/276/scatter-plots-for-exploratory-analysis/5/write-a-function-to-create-multiple-scatter-plots

My Code:>>>
create_scatter <- function(x, y) {
ggplot(data = reviews_2) +
aes_string(x = x, y = y) +
geom_point(alpha = 0.3) +
xlim(1,5) +
ylim(1,5) +
theme(panel.background = element_rect(fill = “white”))
}

x_var <- names(reviews_2)[5]
y_var <- names(reviews_2)[2:4]

map2(x_var, y_var, create_scatter)

What I expected to happen:
3 scatterplots,

What actually happened:
3 scatterplots. The actual seems to match the expected, but I am getting a message that my first scatterplot does not match. This is the code copied from the answer.

Hi @alasdairvan,
when I run your code, I have a PASS. That’s weird

Hi @alasdairvan. I suggest adding a comment to your code. This will clear the code cache and run the code again, which should result in the correct answer. For example,

# This comment will clear your code cache
create_scatter <- function(x, y) {
  ggplot(data = reviews_2) + 
    aes_string(x = x, y = y) +
    geom_point(alpha = 0.3) +
    xlim(1,5) +
    ylim(1,5) +
    theme(panel.background = element_rect(fill = "white"))
}

x_var <- names(reviews_2)[5]
y_var <- names(reviews_2)[2:4]

map2(x_var, y_var, create_scatter)

Please let me know if this does not fix it for you. Best,
-Casey

Hi @casey thank you for your suggestion! I gave it a try and got the same error message.

Hi @alasdairvan. I apologize for the inconvenience! I have been unable to reproduce the issue on my end. Here’s what I’d suggest next…(1) copy and paste the code from the Answer section and submit that code and only that code. If that fails, you may need to start at screen 1 and copy-and-paste the answer code from each screen through this screen, screen 5.

It’s possible that code submitted during a previous code attempt changed an environment setting causing a mis-match between the submission and the answer, even though the plots look identical.

Thanks @casey , starting at screen one and using only the answer code for each screen worked. I appreciate the help!

1 Like

Thanks for letting me know @alasdairvan. I’m sorry for the extra steps, but glad it worked out!

The example given has the curly brackets different to the answer when applying the aesthetics.

Example

 ggplot(data = reviews_2,
    aes(x = x, y = y))

Answer

 ggplot(data = reviews_2) + 
    aes_string(x = x, y = y)
1 Like