boxplots to compare variables

Here is my code:
boxplot(hers$exercise ~ hers$glucose, xlab = "Exercise", ylab= "Glucose")
I am trying to put together boxplots to compare variables.
When I hit enter after typing my code in an R Markdown doc, it just spits it out in blue in the Console below. Why?

Difficult to say since there are ~ 25 screen colour layouts. Sounds like an error but we would need to see the output.

What we need is a FAQ: How to do a minimal reproducible example ( reprex ) for beginners
handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need.

I tried the code again (simply re-opened the RMarkdown doc and clicked on corresponding green arrow to run current code chunk) and here is an image of the wonky boxplot I got in response.

It seems that you have very very many Exercises, and if each is to be a box in your chart, on a typical document, it seems that this would be an impossible task to make it look good...
Perhaps you can use some grouping method and plot only the most similar exercises together, i.e. more charts.

Please supply some data. A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need.

Use dput to supply sample data.

dput(mydata)
structure(list(xx = c(9L, 9L, 5L, 4L, 4L, 2L, 3L, 1L, 8L, 8L, 
3L, 8L, 5L, 3L, 1L, 4L, 7L, 3L, 5L, 4L), yy = c("A", "B", "C", 
"B", "C", "A", "A", "A", "A", "A", "A", "B", "B", "C", "B", "B", 
"B", "C", "A", "B")), class = "data.frame", row.names = c(NA, 
-20L))

I, then, can do

dat1  <- structure(list(xx = c(9L, 9L, 5L, 4L, 4L, 2L, 3L, 1L, 8L, 8L, 
3L, 8L, 5L, 3L, 1L, 4L, 7L, 3L, 5L, 4L), yy = c("A", "B", "C", 
"B", "C", "A", "A", "A", "A", "A", "A", "B", "B", "C", "B", "B", 
"B", "C", "A", "B")), class = "data.frame", row.names = c(NA, 
-20L))

with(dat1,boxplot(xx))
# or 
boxplot(xx ~ yy, data = dat1, col = "red")

Without your data in dput() format we cannot help you.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.