0

I have a bar chart, where the X axis has the city and the Y axis has the automatically determined count of the cities appearing in the data.

    bigger_data <- read.csv(file.choose()) ## public_record_2_xlax
    bigger_data <- drop_na(bigger_data)

    bigger_data %>% arrange(Total.Value) %>%
      ggplot(aes(x=City)) +
      geom_bar()

Is there any way to access the value of the count variable on the Y-axis?

enter image description here

  • 2
    You shouldn't try to extract variables from a plot object. `table(bigger_data$City)` should do what you want, or `bigger_data %>% count(City)` if you prefer tidyverse – Allan Cameron Mar 22 '23 at 16:08
  • I added a new variable, count2, and extracted the value as you said. `count2 <- table(bigger_data$City)` When I put this value in the Y argument of the GG plot, it says the length is not the same, it should graph the same bar plot. `bigger_data %>% arrange(Total.Value) %>% ggplot(aes(x=City, y=count2)) + geom_bar()` Isn't should graph the same? – Humberto Hernandez Mar 22 '23 at 16:29
  • 1
    Try `count2 <- bigger_data %>% count(City)` Then you could have `ggplot(count2, aes(City, n)) + geom_col()` – Allan Cameron Mar 22 '23 at 16:32

0 Answers0