How can I make this histogram in ggplot/R?


Crimea

Please find My data qbelow .

I have two covariates: q$Studieand q$best.respcorresponding to each of the five different studies reporting the best response after a certain treatment.

q$best.respThere are three levels

table(q$best.resp)

 0  1  2 
62 42  2  

I would like to generate a histogram representing each q$best.respof all q$Studieand all study combinations (corresponding to table(q$best.resp))

I've drawn this example of how I want the plot to look. Unfortunately, I didn't have success with the manual.

enter image description here

I prefer the solution in ggplot2. Note that all studies contain only q$best.resp==0or q$best.resp==1-, but both cases aloneq$Studie==5q$best.resp==2

My data 
q <- structure(list(Studie = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L), best.resp = c(0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 
1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 
1L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 2L, 0L, 2L)), .Names = c("Studie", 
"best.resp"), class = "data.frame", row.names = c(NA, -106L))
Roman

You can trytidyverse

library(tidyverse)
q %>% 
  as_tibble() %>% 
  mutate(Studie=as.character(Studie),
         best.resp =as.factor(best.resp)) %>% 
  bind_rows(., mutate(., Studie="all")) %>% 
  count(Studie, best.resp) %>% 
  ggplot(aes(Studie, n, fill= best.resp)) + 
   geom_col(position = position_dodge2(preserve = "single"))

enter image description here

Related


How can I make this histogram in ggplot/R?

Crimea Please find My data qbelow . I have two covariates: q$Studieand q$best.respcorresponding to each of the five different studies reporting the best response after a certain treatment. q$best.respThere are three levels table(q$best.resp) 0 1 2 62 42

How can I make the Gaussian normal match the histogram?

Sam Sloan I was wondering if there is a good way to match Gaussian normals in the form of numpy arrays with a histogram np.histogram(array, bins). How can I draw such a curve on the same graph and adjust it in height and width according to the histogram? Andre

How can I make the Gaussian normal match the histogram?

Sam Sloan I was wondering if there is a good way to match Gaussian normals in the form of numpy arrays with a histogram np.histogram(array, bins). How can I draw such a curve on the same graph and adjust it in height and width according to the histogram? Andre

How can I make the Gaussian normal match the histogram?

Sam Sloan I was wondering if there is a good way to match Gaussian normals in the form of numpy arrays with a histogram np.histogram(array, bins). How can I draw such a curve on the same graph and adjust it in height and width according to the histogram? Andre

How can I make the Gaussian normal match the histogram?

Sam Sloan I was wondering if there is a good way to match Gaussian normals in the form of numpy arrays with a histogram np.histogram(array, bins). How can I draw such a curve on the same graph and adjust it in height and width according to the histogram? Andre

How can I make the Gaussian normal match the histogram?

Sam Sloan I was wondering if there is a good way to match Gaussian normals in the form of numpy arrays with a histogram np.histogram(array, bins). How can I draw such a curve on the same graph and adjust it in height and width according to the histogram? Andre

How can I fix the histogram

aa I am trying to draw a very simple histogram using python. Here is my code: from numpy import * from matplotlib.pyplot import* from random import* nums = [] N = 10 for i in range(N): a = randint(0,10) nums.append(a) bars= [0,1,2,3,4,5,6,7,8,9] hist(

How can I fix the histogram

aa I am trying to draw a very simple histogram using python. Here is my code: from numpy import * from matplotlib.pyplot import* from random import* nums = [] N = 10 for i in range(N): a = randint(0,10) nums.append(a) bars= [0,1,2,3,4,5,6,7,8,9] hist(

How can I reduce the width of the histogram?

Itsuyama I have plotted a histogram of diagnostics, which I modeled as a Poisson distribution in python. I need to reduce the width of the rectangles in the output graph. I wrote the following line in python. I need the width reduction parameter for this line

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I reduce the width of the histogram?

Itsuyama I have plotted a histogram of diagnostics, which I modeled as a Poisson distribution in python. I need to reduce the width of the rectangles in the output graph. I wrote the following line in python. I need the width reduction parameter for this line

How can I represent the classes on the histogram with colors?

Subhankar Nayak I have a column in a dataset which I represent with a pyplot.hist graph. Use grey as a trash can. Another column by which I want to divide the graph is called "Class". There are two categories (0 and 1) in the Category column. I would like to r

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I create a histogram in R?

sara I'm new to working in Unix, so I need help on how to put a histogram together using R in Linux environment? File: 48302 50 0 48303 46 0 48304 45 0 48305 41 15 48306 44 21 48307 74 0 48308 71 0 48309 35 19 48310 66 0 48311 26

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I represent the classes on the histogram with colors?

Subhankar Nayak I have a column in a dataset which I represent with a pyplot.hist graph. Use grey as a trash can. Another column by which I want to divide the graph is called "Class". There are two categories (0 and 1) in the Category column. I would like to r

How can I represent the classes on the histogram with colors?

Subhankar Nayak I have a column in a dataset which I represent with a pyplot.hist graph. Use grey as a trash can. Another column by which I want to divide the graph is called "Class". There are two categories (0 and 1) in the Category column. I would like to r

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10