Question - Problem creating geom_boxplot from data set

Hello, I want to create a boxplot from a dataset similar to the following:

  • Date | Sales | Sales Rep
    08/02 | 600 | Mike
    08/02 | 400 | Jim
    08/03 | 750 | Mike
    08/03 | 450 | Jim

Comparing the "Sales" from the different "Sales Rep".

The issue I'm facing is that I can't get the graph to combine the "Sales" from the several days ("Date") into the respective "Sales Rep".

What are my options to make this work?

Ps. Sorry, I'm not allowed to post a picture of the real table.

library(ggplot2)
library(readxl)
library(tidyverse)

test_boxplot <- read_excel("C:/Users/Usuario/Desktop/test_boxplot.xlsx",
                          col_types = c("date", "skip", "skip", "skip", "skip",
                            "skip", "numeric", "text"))

test_boxplot %>%
  ggplot(aes(x = 'Sales Rep',y = Total,group_by('Sales Rep'),fill = 'Sales Rep')) +
  geom_boxplot()
#> Warning: Removed 33 rows containing non-finite values (stat_boxplot).

Created on 2020-08-03 by the reprex package (v0.3.0)

This code works for me.

library(ggplot2)
DATES <- seq.Date(from = as.Date("2020-08-01"), to = as.Date("2020-08-20"), by = 1)
DF <- data.frame(Date = rep(DATES, each = 2), `Sales Rep` = rep(c("Mike", "Dave"), 10),
                 Sales = runif(40, 50, 100), check.names = FALSE)
head(DF)
ggplot(DF, aes(x = `Sales Rep`, y = Sales, fill = `Sales Rep`)) + geom_boxplot()

Try using back ticks, `, instead of single quotes, ', around Sales Rep. The back tick key is just to the left of the 1 key on a US keyboard.
Even better, do not use column names with spaces or other non syntactic characters. It causes more trouble than it is worth, I think.

Hi FJCC,

Your code worked, thanks.

However, the table I have is a little more complex and some names appearing every day, and some don't. Do you recommend me to create a new data frame based on the info of the table or importing should work?

Is it possible to make this table available here?

The table is confusing as the user created it.

Hi FJCC,

I reworked the data and got the code running.

Thank you.

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