Reputation: 11
Just yesterday select was working just fine on the top half of the code but not that is not working.
# pulling libraries
library('dplyr')
library('ggplot2')
# reading the data
data <- read.csv('week2_dataset.csv')
#looking at the data
data
#viewing the data in a more pretty way
View(data)
#selecting variables
data %>%
#selecting the variable, group, total, and insured columns
select (variable, group, total, insured, uninsured) %>%
#filtering by race age and sex, my 3 picked variables
filter(variable %in% c('race', 'age', 'sex')) %>%
mutate(percent_insured = insured / total) %>%
mutate(percent_uninsured = uninsured / total) %>%
mutate(least_insured = ifelse (percent_insured <0.9, 1, 0)) %>%
mutate (most_insured = ifelse (percent_insured >0.9, 1, 0)) %>%
mutate (most_least = ifelse (least_insured <0.9, "most", "least"))
print(data)
data
ggplot(data = viz,
aes (x = group, y = insured)) +
geom_col() +
geom_text(vjust = -1)
The bottom half I can't get ggplot to work.
Here is some troubleshooting data:
dput(head(data))
structure(c("function (..., list = character(), package = NULL, lib.loc = NULL, ",
" verbose = getOption(\"verbose\"), envir = .GlobalEnv, overwrite = TRUE) ",
"{", " fileExt <- function(x) {", " db <- grepl(\"\\\\.[^.]+\\\\.(gz|bz2|xz)$\", x)",
" ans <- sub(\".*\\\\.\", \"\", x)"), dim = c(6L, 1L), dimnames = list(
c("1", "2", "3", "4", "5", "6"), ""), class = "noquote")
>
Thank you for the help! extremely novice r-studio user here.
Upvotes: 0
Views: 224
Reputation: 683
First, You don't need to use the mutate function multiple times. you can simply create a variable, and then just add a comma (,) and create another variable.
Second, You did not assign all these changed back to data. you need to start all this big changes pipeline with a 'data <-'.
Lastly, I could'nt make use of your dummy code so i didnt check it myself, but try to get rid of the geom_text (In most cases you should have a label argument with it). Solve the assigning part + get rid of the text, and see if it works. Otherwise code looks just fine :)
Upvotes: 1