0

This question was not asked correctly and is no longer relevant.

barnsm2
  • 175
  • 7
  • Please make this a reproducible issue by sharing some of your data and the code you've tried so far. See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for tips on how to post a good question. – Dan Adams Feb 17 '22 at 18:52

1 Answers1

1

Please upload a dataset for us to work with next time.

The answer you are looking for is quite simple, it's in the package library(dplyr)using the command filter()

Since I don't have your dataset, I made one up, with four races, under the column "bwt", and the other column, I called "height", this is what you will make a histogram with

# Create an empty data frame with column names
example_df <- data.frame( "bwt" = character(0), "height" = integer(0))
#Assign names to x 
variable_names <- c( "Black", "White", "Native-American", "Other")
# Assign names to y
w<-rnorm(200, mean=5, sd=2)
x<-rnorm(200, mean=5, sd=2)
y<-rnorm(200, mean=5, sd=2)
z<-rnorm(200, mean=5, sd=2)
#combine everything to create dataframe (df)
df <- data.frame( "btw" = variable_names, "height" = c(w,x,y,z))
attach(df)
#load necessary package
library(dplyr)
# Use the filter() command to select the races you want
black = filter(df,btw=="Black")
white = filter(df,btw=="White")
native = filter(df,btw=="Native-American")
other = filter(df,btw=="Other")
# make histograms (I will only upload one image as an example here)
hist(black$height)
hist(white$height)
hist(native$height)
hist(other$height)

[![enter image description here][1]][1]

# you can also plot all 4 in one window

par(mfrow = c(2, 2), cex = 1)

hist(black$height,col="blue")
hist(white$height, col="green")
hist(native$height, col="orange")
hist(other$height, col="grey23")

'''

[![enter image description here][2]][2]


  [1]: https://i.stack.imgur.com/OuWkx.png
  [2]: https://i.stack.imgur.com/t5rDp.png
Andy
  • 379
  • 1
  • 12