I have a dataset like this. The data has been collected through a questionnaire and I am going to do some exploratory data analysis.windows <- c(yes, no,yes,yes,no)sql     <- c(no,yes,no,no,no)excel  <- c(yes,yes,yes,no,yes)salary <- c(100,200,300,400,500 )test<- as.data.frame (cbind(windows,sql,excel,salary),stringsAsFactors=TRUE)test[,salary] <- as.numeric(as.character(test[,salary] ))I have an outcome variable (salary) in my dataset and a couple of input variables (tools). How can I visualize a horizontal box plot like this:
visualize a horizontal box plot in R
r;visualization
Let's start by creating some fake dataset. software = sample(c(Windows,Linux,Mac), n=100, replace=T) salary = runif(n=100,min=1,max=100) test = data.frame(software, salary)This should create a dataframe test that will look like somewhat like:     software    salary1    Windows 96.6972172      Linux 29.7709053    Windows 94.2496124        Mac 71.1887015      Linux 94.0283266      Linux  7.4826327        Mac 98.8416898        Mac 81.1526239    Windows 54.07376110   Windows  1.707829EDIT based on comment Note that if the data does not already exist in the above format, it can be changed to this format. Let's take a data frame provided in the original question and lets assume the dataframe is called raw_test.    windows sql excel salary1     yes  no   yes    1002      no  yes  yes    2003     yes  no   yes    3004     yes  no    no    4005      no  no   yes    500Now, using the melt function/ method from the reshape package in R, first create the dataframe test (that will be used for final plotting) as follows: # use melt to convert from wide to long format test = melt(raw_test,id.vars=c(salary))# subset to only select where value is yestest = subset(test, value == 'yes')# replace column name from variable to software names(test)[2] = software   Now, you will get a datframe test that looks like:   salary software value1     100  windows   yes3     300  windows   yes4     400  windows   yes7     200      sql   yes11    100    excel   yes12    200    excel   yes13    300    excel   yes15    500    excel   yesHaving created the dataset. We will now generate the plot. First, create the bar plot on the left based on the counts of software that represents usage rate. p1 <- ggplot(test, aes(factor(software))) + geom_bar() + coord_flip()Next, create the boxplot on the right. p2 <- ggplot(test, aes(factor(software), salary)) + geom_boxplot() + coord_flip()Finally, place both these plots next to each other. require('gridExtra')grid.arrange(p1,p2,nrow=1)This should create a plot like: 