Hi, and welcome!
Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers.
Although it's not in the preferred reprex
format which is best for cut and past, the code is fine except for one major shortcoming -- the data object, df
.
Because this is a relatively short and simple data set, rather than a screenshot, which is seldom useful, what would be helpful is to
dput(df)
and copy/paste after entering
df <- [paste here]
A shortcut direct to clipboard is
require(clipr)
#> Loading required package: clipr
#> Welcome to clipr. See ?write_clip for advisories on writing to the clipboard in R.
require(magrittr)
#> Loading required package: magrittr
require(stringr)
#> Loading required package: stringr
specimen <- function(x)
deparse(x) %>%
str_c(collapse = '') %>%
str_replace_all('\\s+', ' ') %>%
str_replace_all('\\s*([^,\\()]+ =) (c\\()', '\n \\1\n \\2') %>%
str_replace_all('(,) (class =)', '\\1\n \\2') %>%
write_clip(allow_non_interactive = TRUE)
specimen(dat)
A few suggestions for redoing this
library(ggplot2) # should go first
df <- [paste]
colnames(df) <- c("modality","First_response","Second_response","Third_response","Fourth_response,"Sixth_response")
ggplot(df, aes(x = modality) # df is already a data frame