Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hope-data-science opened this issue Oct 17, 2024 · 0 comments
Open

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

hope-data-science opened this issue Oct 17, 2024 · 0 comments

Comments

@hope-data-science
Copy link

给出了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()  # 移除图例边框
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant