【问题标题】:How to provide a visual breakdown of the liquor category in this R code如何在此 R 代码中提供酒类类别的可视化细分
【发布时间】:2022-11-03 00:33:30
【问题描述】:

我使用以下代码将我的数据上传到 R

if (!file.exists("ames-liquor.rds")) {
  url <- "https://github.com/ds202-at-ISU/materials/blob/master/03_tidyverse/data/ames-liquor.rds?raw=TRUE"
  download.file(url, "ames-liquor.rds", mode="wb")
}
data <- readRDS("ames-liquor.rds")

然后使用此代码提取地理纬度和经度

ata <- data %>% 
  separate(remove= FALSE,
           col = 'Store Location' , sep=" ",
           into=c("toss-it", "Latitude", "Longitude"))
data <- data %>% mutate(
  Latitude = parse_number(Latitude),
  Longitude = parse_number(Longitude)
)

现在我需要

Plot a scatterplot of lat and long of store locations. 
  - Provide a visual breakdown of the liquor category (by `Category Name`). Include volume sold in the breakdown. Make sure that all labels are readable

对于它的第一部分,我做了这个

data %>%
  ggplot(aes(x = Latitude, y = Longitude))+
  geom_point(na.rm = TRUE)

但我似乎无法找到如何


  - Provide a visual breakdown of the liquor category (by `Category Name`). Include volume sold in the breakdown. Make sure that all labels are readable.

我将衷心感谢您的帮助

【问题讨论】:

  • ggplot 调用的aes() 部分中添加color = `Category Name`

标签: r statistics r-markdown


【解决方案1】:

您应该能够为美学提供另一个变量,使颜色进入标签,如下所示:

data %>%
 ggplot(aes(x = Latitude, y = Longitude, color=`Category Name`))+
 geom_point(na.rm = TRUE)

这将提供颜色并且应该告诉ggplot2 添加一个图例。

【讨论】:

    猜你喜欢
    • 2018-03-15
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    • 1970-01-01
    • 2021-01-05
    • 2022-08-20
    • 2012-07-15
    • 2021-05-08
    相关资源
    最近更新 更多