When trying to plot a histogram for a class project, I keep getting an error message saying 'x must be numeric.' I am trying to plot a histogram of Democratic vote share (which I created a variable for as dem_pct) in open-seat races (df$inc_D==0 & df$inc_R==0) and races with a Democratic incumbent (df$inc_D==1). I checked to see which variables are coming back as non-number, and that is the "state" column, which I expected. I have been trying to create a new variable "Dem_Inc" to represent the vote share during years with Dem Incumbents, with OpenSeat meant to represent years without an incumbent.
I have the following code for a histogram I am trying to use:
hist(my_data$my_variable, breaks = 20, main= "PLOT TITLE", xlab= "X-AXIS TITLE")
Here are the variables in this dataset:
> names(df)  "state" "year" "dist"  "vote_D" "inc_D" "vote_R"  "inc_R" `` Here is my full code `library(tidyverse) library(dplyr) df <- read.csv("C:/Users/brand/downloads/house.csv") dem_pct <- 100*df$vote_D/(df$vote_D + df$vote_R) mean(dem_pct) mean(dem_pct[df$inc_D==1]) mean(dem_pct[df$inc_R==1]) mean(dem_pct[df$inc_D==0 & df$inc_R==0]) filter(df, df$inc_D==1,) filter(df, df$inc_R==0 & df$inc_D==0) Inc_Dem <- filter(df, df$inc_D==1) OpenSeat <- filter(df, df$inc_R==0 & df$inc_D==0) sapply(df, class) sapply(df, is.factor) sapply(df, is.numeric) names(df) Dem_Inc <- df$inc_D==1 OpenSeat <- df$inc_R==0 & df$inc_D==0``