The code I've used is:
mcgc <- ggplot(sam, aes(x = person,y = m, colour = X)) +
geom_point(size = 0.75) +
scale_colour_gradient2(high="red", mid="green", limits=c(0,1), guide = "colourbar") +
geom_hline(aes(yintercept = mad, linetype = "mad"), colour = "blue", size=0.75, show_guide = TRUE) +
geom_hline(aes(yintercept = mmad, linetype = "mmad"), colour = "black", size=0.75, show_guide = TRUE) +
facet_wrap(~ Plan, scales = "free", ncol = 4) +
scale_linetype_manual(name = "Plan of Health Care", values = c("mad" = 1, "mmad" = 1),guide = "legend")
For this data:
Plan person X m mad mmad
1 1 95 0.323000 0.400303 0.12
1 2 275 0.341818 0.400303 0.12
1 3 2 0.618000 0.400303 0.12
1 4 75 0.320000 0.400303 0.12
1 5 13 0.399000 0.400303 0.12
1 6 20 0.400000 0.400303 0.12
2 7 219 0.393000 0.353350 0.45
2 8 50 0.060000 0.353350 0.45
2 9 213 0.390000 0.353350 0.45
2 15 204 0.496100 0.353350 0.45
2 19 19 0.393000 0.353350 0.45
2 24 201 0.388000 0.353350 0.45
3 30 219 0.567 0.1254 0.89
3 14 50 0.679 0.1254 0.89
3 55 213 0.1234 0.1254 0.89
3 18 204 0.6135 0.1254 0.89
3 59 19 0.39356 0.1254 0.89
3 101 201 0.300 0.1254 0.89
I'm trying to manipulate the x axis using:
scale_x_continuous(breaks = c(min(person), median(person), max(person)), labels = c(min(person), median(person), max(person)))
However, given that I had to change person
into a factor to order the data properly, the above code does not work. I get the errors, depending on how I fiddle around with the code:
Error: Discrete value supplied to continuous scale
Error in Summary.factor(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, :
min not meaningful for factors
Changing person
to numeric does not work, as the accumulated person
for the entire dataset will then be on each Plan figure panel, as opposed to the scale specific for each Plan.
Is there a workaround for this?
Build the plots separately and group them with functions from the
gridExtra
package.