简体   繁体   English

R-ggplot2“错误:出现意外符号:”

[英]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). 我想在散点图上绘制$ Month的$ Number of Deaths,并最终通过$ State绘制facet_wrap,但这不是我遇到的问题。

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" 错误:出现意外符号:“ ggplot(数据=死亡人数)+ geom_point(映射= aes(x =月,y =数量)

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 这是我正在使用的数据集: 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. 用坟墓/反引号(`)包裹它们,以使R清楚地知道它是单个名称。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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