简体   繁体   中英

R - ggplot2 “error: unexpected symbol in:”

I'm trying to do what in theory should be the easiest thing ever but i'm making some mistake that I can't even understand.

I would like to plot $Number of Fatalities by $Month on a scatterplot, (and eventually facet_wrap by $State but that's not where i'm having issues).

Here is my attempt:

 library(tidyverse) fatalities <- read.csv(filename.csv) fatalities = as.data.frame(fatalities) ggplot(data = fatalities)+ geom_point(mapping = aes(x = Month, y = Number of Fatalities)) 

...and here is the output:

Error: unexpected symbol in: "ggplot(data = fatalities) + geom_point(mapping = aes(x = Month, y = Number of"

This is the dataset i'm using: https://data.gov.au/dataset/5b530fb8-526e-4fbf-b0f6-aa24e84e4277/resource/0e3771a4-4783-4a12-89ac-b48892bb3ba0/download/bitrearddfatalcrashesfebruary2018.csv

Your help with this or how I could rephrase the question is greatly appreciated - thank you!

Can't have spaces in variable names. Wrap them with graves/backticks (`) to make it clear to R that it is a single name.

geom_point(mapping = aes(x = Month, y = `Number of Fatalities`))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM