ggplot2 - R: How to spread (jitter) points with respect to the x axis? -


i have following code snippet in r:

dat <- data.frame(cond = factor(rep("a",10)),                    rating = c(1,2,3,4,6,6,7,8,9,10)) ggplot(dat, aes(x=cond, y=rating)) +   geom_boxplot() +    guides(fill=false) +   geom_point(aes(y=3)) +   geom_point(aes(y=3)) +   geom_point(aes(y=5)) 

this particular snippet of code produces boxplot 1 point goes on (in above case 1 point 3 goes on point 3).

how can move point 3 point remains in same position on y axis, moved left or right on x axis?

this can achieved using position_jitter function:

geom_point(aes(y=3), position = position_jitter(w = 0.1, h = 0)) 

update: plot 3 supplied points can construct new dataset , plot that:

points_dat <- data.frame(cond = factor(rep("a", 3)), rating = c(3, 3, 5))                   ggplot(dat, aes(x=cond, y=rating)) +   geom_boxplot() +    guides(fill=false) +   geom_point(aes(x=cond, y=rating), data = points_dat, position = position_jitter(w = 0.05, h = 0))  

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -