I have overlaid density plots (of boys vs girls) in a ridgeline density plot. The X axis values are whole numbers ranging from 1 to 9 but in the density plot they are smoothed to go from 0 to 10. Also the X axis displays decimal values such as 2.5 and 7.5.
- Is there anyway to ensure only whole number values are displayed and no fractional values?
- Can I control the display to only range from 1 to 9 and not have the 0 and 10 portionas : in other words only display the portion of the graph between the values 1 and 9?
Here is some sample data:
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)
Here is the code I am using:
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)