以下是一个示例代码:

library(ggplot2)

# 创建数据框
df <- data.frame(x = runif(50), y = runif(50))

# 转换为百分数
df$x <- paste0(round(df$x * 100), '%')
df$y <- paste0(round(df$y * 100), '%')

# 绘制散点图
ggplot(df, aes(x = x, y = y)) +
  geom_point() +
  scale_x_discrete(labels = function(x) str_replace_all(x, '%', '')) +
  scale_y_discrete(labels = function(y) str_replace_all(y, '%', '')) +
  labs(x = 'X轴', y = 'Y轴')

这会生成一个散点图,其中 x 和 y 轴都用百分数标记。请注意,我们使用 scale_x_discrete()scale_y_discrete() 函数来设置轴标签,并使用 str_replace_all() 函数删除百分号。

R语言ggplot2绘制百分数散点图

原文地址: http://www.cveoy.top/t/topic/nj5r 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录