Skip to content

参考答案新版本B.12 #32

Open
@hope-data-science

Description

@hope-data-science

给出了B.12版本的注释,供参考:

library(tidyverse)
set.seed(12)

d1 <- data.frame(x = rnorm(50, 10, 2), type = "Island #1")
d2 <- data.frame(x = rnorm(50, 18, 1.2), type = "Island #2")

dd <- bind_rows(d1, d2) %>%
  set_names(c("Height", "Location"))

# 绘制直方图并根据要求进行修改
dd %>%
  ggplot(aes(x = Height, fill = Location)) +
  geom_histogram(binwidth = 1, color = "white") +
  scale_fill_manual(values = c("green3", "turquoise3")) +
  scale_y_continuous(expand = c(0, 0)) +  # 移除X轴间隙 
  labs(x = "Height", y = "Count") +  # 保持轴标签不变
  theme_minimal() +  # 使用最简化的主题
  theme(
    axis.title = element_text(size = 14),  # 修改轴标题的字体大小
    # 去除面板边框
    panel.border = element_blank(),
    # 去除网格线
    panel.grid = element_blank(),
    # 设置图例位置
    legend.position = c(0.1, 0.9),
    legend.title = element_blank(),  # 移除图例标题
    legend.background = element_blank(),  # 移除图例的背景
    legend.key = element_blank()  # 移除图例边框
  )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions