-2

I just started learning R and can't figure out how to plot histogram of Gender (Male Female Other, all categorical on x axis) and the Reaction time (numeric,y axis). Also, need to show distribution of reaction times between genders. Thanks.

Monika
  • 1
  • 1
  • 2
    Welcome to SO Monika. Please include some data to make your problem [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This will make it much easier for others to help you. – markus Nov 21 '18 at 21:07

1 Answers1

0

stripchart Using a histogram for a variable with three levels, as in your case, is difficult. Maybe a more fitting graph is a stripchart. Let's assume you have a data frame structured roughly similarly to this one:

df <- data.frame(
  Gender = c(rep("male", 33), rep("female", 33), rep("other", 34)),
  Reaction_time = c(rnorm(100)^2)
  )
head(df)
  Gender Reaction_time
1   male     0.1041879
2   male     0.0125468
3   male     0.8123625
4   male     0.2690723
5   male     1.0718162
6   male     2.5211264

then you could plot the reaction times nicely in a stripchart:

par(mar=c(4,4,1,4)) # set the margins of the plot
stripchart(df$Reaction_time~df$Gender, # plot the two variables against each other 
method="jitter", # avoid overplotting
       xlab="Reaction time", # label the x-axis
       ylab="Gender") # label the y-axis
Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34