Cant find distance object

My script cannot find the object "distance" that is in my csv file. I am trying to limit the results in miles from 0-600,000 down to results < 5000.

csv import

library(readr)
ArendasB <- read_csv("C:/Users/qdibs/Desktop/Spring 2021/MATH 216/ArendasB.csv")
View(ArendasB)

generate plot

library(ggplot2)
ggplot(ArendasB, aes(x=city, y=distance)) + geom_boxplot()+
coord_flip()+labs(y="distance(miles)")+theme_bw()+
ggtitle("Figure 3: Estimated distance by city", labs
(caption= "Brandon Arendas - Section 002"))+scale_y_continuous(labels = function(y)
format(y, scientific = FALSE))

g3 + ArendasB=filter(ArendasB,distance<5000)

Gives the error code: Error in filter(ArendasB, distance < 5000) : object 'distance' not found.

Do you mean you want to limit only on the plot or you want to filter the data too, < 5000 miles?

adding +xlim(0, 5000) on your graph code above will limit the graph x-axis plot to 5000.

If you want to filter the data and run the graph code again,
library(tidyverse)
ArendasB%>% filter (distance< 5000)%>% ggplot((ArendasB%>% filter (distance< 5000), aes(x=city, y=distance)) + geom_boxplot()+
coord_flip()+labs(y="distance(miles)")+theme_bw()+
ggtitle("Figure 3: Estimated distance by city", labs
(caption= "Brandon Arendas - Section 002"))+scale_y_continuous(labels = function(y)
format(y, scientific = FALSE))

I would like to filter the data using the dplyr package to only display results less than 5000 miles. Are u able to use dplyr instead of tidyverse?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.