Making a pair of inverted histogram

I want to make pairs of dot plot histograms for two groups in a different set of tests, where the two groups are displayed in opposite directions on the y-axis. Use this simple data Set

dat <- data.frame(score = rnorm(100), group = rep(c("Control", "Experimental"), 50), test = rep(LETTERS[1:2], each=50))

I can make faceted dot plots like this

ggplot(dat , aes(score, fill=group)) + facet_wrap(~ test) + geom_dotplot(binwidth = 1, dotsize = 1)

But I want the control point to point down instead of up. Use this question and answer , I can make a version of the histogram that looks more or less the same as I want

ggplot() + 
geom_histogram(data=subset(dat, group =="Experimental"), aes(score, fill="Experimental", y= ..count..)) +
geom_histogram(data=subset(dat, group=="Control"), aes(score , fill="Control", y= -..count..)) +
scale_fill_hue("Group")

But now the face has disappeared. I know I can use grid.arrange Faceting manually, but it is laborious (my actual data set has a lot of tests, not just 2), is there a more elegant solution?

Two follow-up questions:

> geom_histogram is giving me a warning, which says "The stack is not clear when ymin!=0". Does anyone know how it is "No Clearly defined? In other words, is this something I should be concerned about?
>I prefer to use dotplot instead of histogram, but inversion does not seem to work with dotplot. Why is this? Any ideas how to make it work?

Thanks in advance!

Reading geom_dotplot carefully will bring benefits:

ggplot() +
facet_wrap(~test) +
geom_dotplot(data=subset(dat, group=="Experimental"), aes(score, fill="Experimental")) +
geom_dotplot(data=subset(dat, group=="Control"), aes(score, fill="Control"),stackdir = "down") +
scale_fill_hue("Group")< /pre>

I don't know the stackdir argument above my head. I have to check it!

I want to make pairs of dot plot histograms for two groups in a different set of tests, where the two groups are displayed in opposite directions on the y-axis. This simple data set

dat <- data.frame(score = rnorm(100), group = rep(c("Control", "Experimental") , 50), test = rep(LETTERS[1:2], each=50))

I can make faceted dot maps like this

ggplot(dat, aes(score, fill=group)) + facet_wrap(~ test) + geom_dotplot(binwidth = 1, dotsize = 1)

But I want the control point to point down instead of up. Use In this question and answer, I can make a version of the histogram that looks more or less the same as I want

ggplot() + 
geom_histogram(data=subset (dat, group=="Experimental"), aes(score, fill="Experimental", y= ..count..)) +
geom_histogram(data=subset(dat, group=="Control") , aes(score, fill="Control", y= -..count..)) +
scale_fill_hue("Group")

But now the face has disappeared. I know I can Use grid.arrange to facet manually, but it is laborious (my actual data set has a lot of tests, not just 2), is there a more elegant solution?

Two follow-up questions:

> geom_histogram is giving me a warning, which says "The stack is not clear when ymin!=0". Does anyone know how it is "No Clearly defined? In other words, is this something I should be concerned about?
>I prefer to use dotplot instead of histogram, but inversion does not seem to work with dotplot. Why is this? Any ideas how to make it work?

Thanks in advance!

Reading geom_dotplot carefully will bring benefits:

ggplot() +
facet_wrap(~test) +
geom_dotplot(data=subset(dat, group=="Experimental"), aes(score, fill="Experimental")) +
geom_dotplot(data=subset(dat , group=="Control"), aes(score, fill="Control"),stackdir = "down") +
scale_fill_hue("Group")

I don’t know what’s above my head The stackdir argument. I have to check it!

Leave a Comment

Your email address will not be published.