我在山脊线密度图中覆盖了(男孩与女孩的)密度图。X 轴值是从 1 到 9 的整数,但在密度图中,它们被平滑为从 0 到 10。X 轴也显示十进制值,例如 2.5 和 7.5。
- 有没有办法确保只显示整数值而不显示小数值?
- 我可以控制显示范围仅从 1 到 9 并且没有 0 和 10 部分:换句话说,仅显示值 1 和 9 之间的图形部分?
以下是一些示例数据:
rank<-c(1,2,3,1,5,7,4,6,8,9,1,2,4,5,6,3,8,7,9,3)
gender<-c("M","M","M","M","M","M","M","M","M","M",
"F","F","F","F","F","F","F","F","F","F")
time<-c(1,2,3,4,1,2,3,4,3,3,4,4,4,4,1,1,1,1,2,3)
data<-data.frame(rank,gender,time)
这是我正在使用的代码:
ggplot(math_dat, aes(x = rank, y = time, color = gender, point_color = gender, fill = gender)) +
geom_density_ridges(
jittered_points = TRUE, scale = .95, rel_min_height = .01,
point_shape = "|", point_size = 3, size = 0.25,
position = position_points_jitter(height = 0)
) +
scale_y_discrete(expand = c(0, 0)) +
scale_x_continuous(expand = c(0, 0), name = "Rankings") +
scale_fill_manual(values = c("#33FFDE50", "#00663350"), labels = c("Girls", "Boys")) +
scale_color_manual(values = c("#33FFDE", "#006633"), guide = "none") +
scale_discrete_manual("point_color", values = c("#33FFDE", "#006633"), guide = "none") +
coord_cartesian(clip = "off") +
guides(fill = guide_legend(
override.aes = list(
fill = c("#33FFDEA0", "#006633A0"),
color = NA, point_color = NA)
)
) +
ggtitle("Ranks over time") +
theme_ridges(center = TRUE)