Warm tip: This article is reproduced from serverfault.com, please click

I'm learning R. I was wondering how I could make a barplot with a data set I've made?

发布于 2020-12-02 18:38:43

Here is the data I've made:

    structure(list(Resort = c("Park City", "Powder Mountain", "Snowbird", 
    "Alta", "Snow Basin", "Deer Valley"), `Named Runs` = c(348, 154, 
    140, 116, 107, 103)), row.names = c(NA, -6L), class = c("tbl_df", 

"tbl", "data.frame"))

Here is my code. I'm trying to get a bar graph, with resorts on the x-axis and named runs on the y-axis. Unfortunately, my graph is only showing resorts. How can I fix this? Thanks.

    library(readxl)
    Utah_ski_resort_data_ <- read_excel("Desktop/Utah ski resort data..xlsx")    
    View(Utah_ski_resort_data_)
    table(Utah_ski_resort_data_$Resort)
    table(Utah_ski_resort_data_$`Named Runs`)
    barplot(table(Utah_ski_resort_data_$Resort)
Questioner
Sam Laski
Viewed
0
eastclintw00d 2020-12-03 03:30:05

barplot with formula:

barplot(`Named Runs` ~ Resort, Utah_ski_resort_data_)

And this is a ggplot2 barplot:

library(ggplot2)
library(dplyr)
Utah_ski_resort_data_ %>% 
  ggplot(aes(x = Resort, y = `Named Runs`)) +
  geom_bar(stat = "identity")