与“错误:美学必须与长度1或与数据相同"相关联的问题. [英] Questions associated with "Error: Aesthetics must be either length 1 or the same as the data"

查看:136
本文介绍了与“错误:美学必须与长度1或与数据相同"相关联的问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解错误:美学必须长度为1或与数据相同"这一主题(已经完成了大量阅读工作,可以在线阅读),但是,我仍然有一些未解决的问题

I understand the subject "Error: Aesthetics must be either length 1 or the same as the data" has been done a lot (plenty of reading available online), however, I still have some unresolved questions

我正在处理有关2015年西雅图警察局所有电话的数据集.完成将数据清理成可接受的格式后,我得到了62,092行和13列的数据集(数据集名称为SPD_2015 ).我会在此问题中添加一部分数据集,但我不完全确定如何以清晰易读的格式进行操作.

I am working with a dataset regarding all calls made to the Seattle Police Department in 2015. After I am done cleaning the data into an acceptable format I wind up with a dataset that is 62,092 rows and 13 columns (dataset name is SPD_2015). I would add a portion of the dataset to this question but I'm not entirely sure how to do it in a clean and legible format.

我使用lubridate软件包提取了与我的数据集相关的时间.然后,我创建了一个条形图,显示了犯罪发生的时间

I used package lubridate to extract the times associated with my data set. I then created a bar graph that showed what time the crimes occur

ggplot(SPD_2015, aes(hour(date.reported.time))) +
  geom_bar(width = 0.7) 

那很好用.

由于汽车四处寻觅是最常报告的犯罪,因此我想说明这些汽车四处寻觅发生的时间.这是当我遇到错误错误:美学:长度必须为1或与数据相同".

Since Car Prowls were the most frequently reported crime, I wanted to graph what time these car prowls occurred. And this is when I come across the error ""Error: Aesthetics must be either length 1 or the same as the data".

当您在ggplot代码中进行子集化时,我了解到ggplot2不喜欢它,因此我通过创建一个单独的数据帧来对数据进行子集化.

I read that ggplot2 does not like it when you subset within the ggplot code, so I subsetted my data by creating a separate data frame.

car.prowl <- filter(SPD_2015, summarized.offense.description == "CAR PROWL")

这是我的问题.为什么当我查看新创建的数据集"car.prowl"的尺寸时,却看到它具有11,539行和13列的尺寸.但是,当我检查事件发生时间"列中的小时数(犯罪发生的时间)时,我得到的长度为62,092,这是原始数据集的长度吗?

So here is my question. Why is it that when I look at the dimensions of my newly created dataset "car.prowl" I see that it has a dimension of 11,539 rows and 13 columns. But when I examine the length of the hours in the occurred.time column (the time that the crime occurred) I get a length of 62,092 which is the length of the original dataset?

在我的脑海中,我想象下面的代码会起作用:

In my mind I am picturing that the following code would work:

ggplot(car.prowl, aes(hour(occured.time))) +
  geom_bar()

car.prowl $ occured.time的长度正确:

The length of the car.prowl$occured.time is correct:

> length(car.prowl$occured.time)
[1] 11539

但是当我应用小时函数时,我得到了原始数据集的长度:

but when I apply the hour function I get the length of the original dataset:

> length(hour(car.prowl$occured.time))
[1] 62092

应该是11539.

谢谢.请让我知道我可以做些什么来使我的问题更清楚.

Thank you. Please let me know what I can do to make my question more clear.

推荐答案

正如杰里米(Jeremy)所说,这可能是一个缓存问题.我不确定这是否行得通,但是您可以尝试以下方法,将它们链接在一起.

It could be a caching issue as Jeremy said above. I'm not sure this would work, but you could try the below, chaining things together.

SPD_2015%>%
 filter(summarized.offense.description == "CAR PROWL")%>%
 ggplot(aes(hour(occured.time)))+
 geom_bar()

这篇关于与“错误:美学必须与长度1或与数据相同"相关联的问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆