如何在 RStudio 中创建此点图?
问问题
69 次
2 回答
0
首先我们需要一些数据。以下与图片中的数据大致匹配:
set.seed(69)
my_data <- rgamma(40, 5, 40)
我们可以ggplot2
像这样绘制它:
library(ggplot2)
ggplot(data.frame(x = my_data, y = 1), aes(x, y)) +
geom_point(size = 5, color = "#579fc4", alpha = 0.5) +
scale_y_continuous(limits = c(0.5, 1.5), breaks = c(0, 2)) +
scale_x_continuous(labels = scales::percent_format(1),
breaks = c(0.05, 0.1, 0.15, 0.2, 0.25),
name = "Interest rate") +
theme_minimal() +
theme(axis.line.x = element_line())
于 2020-10-21T21:25:41.483 回答
0
像这样的东西?
library(tidyverse)
data.frame("Interest_Rate" = runif(n = 40, min = 0, max = 0.25),
"Interest_Rate_y" = rep(1.1, 40),
"Mean_Value_y" = rep(0.21, 40)) %>%
ggplot() +
geom_point(aes(y = Interest_Rate_y, x = Interest_Rate),
size = 10, col = "deepskyblue", alpha = 0.25) +
geom_point(aes(y = Mean_Value_y, x = mean(Interest_Rate)),
size = 8, pch = 17, col = "red") +
geom_hline(yintercept = 0.75) +
coord_cartesian(ylim = c(0,1.5), clip = "off") +
scale_x_continuous(name = "Interest Rate", labels = scales::percent) +
theme_classic(base_size = 16) +
theme(axis.title.y = element_blank(),
axis.text.y = element_blank(),
panel.grid = element_blank(),
axis.line.y = element_blank(),
axis.ticks.y = element_blank())
于 2020-10-21T22:15:37.390 回答