Cannot get ggplot2 to show what I want it to.

I am trying to use ggplot2 to create a group of plots. For some reason neither the x or y axis is plotting correctly. Any and all help and advice is greatly appreciated.

Here is the code I am using.

# Input load. Please do not change #
`dataset` = read.csv('C:/Users/430210/REditorWrapper_592df83b-b2e6-47d6-b395-3a0fa34b099d/input_df_7cb01042-6a48-40b8-a0e5-d334374d3816.csv', check.names = FALSE, encoding = "UTF-8", blank.lines.skip = FALSE);
# Original Script. Please update your script content here and once completed copy below section back to the original editing window #
# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script: 

#  <- data.frame()
#  <- unique()

# Paste or type your script code here:
library(scales)
library(extrafont)
library(tidyverse)
library(lubridate)


loadfonts(device="win")
dataset$WeekStartDate <-ymd(str_sub(dataset$WeekStartDate,1,10))

ggplot(data = dataset , aes(x=WeekStartDate, y=Percentage ))+
  geom_col() +
  facet_wrap(~ Plant,nrow = 1)

I the below image the top visual is what I am getting when I try ggplot2. I have one section of it zoomed in to the left so you can the x-axis values better. The visual with the blue colors is the visual that is created by Power BI using the same dataset.

Here is the dataset I am using.

Blockquote
|Line|WeekStartDate|Percentage|
|---|---|---|
|Line1|2021-06-28T00:00:00.0000000|17.5066313|
|Line1|2021-07-05T00:00:00.0000000|22.71062271|
|Line1|2021-07-12T00:00:00.0000000|44.24057085|
|Line1|2021-07-19T00:00:00.0000000|68.34817013|
|Line1|2021-07-26T00:00:00.0000000|61.95965418|
|Line1|2021-08-02T00:00:00.0000000|22.14983713|
|Line1|2021-08-09T00:00:00.0000000|28.43691149|
|Line2|2021-06-28T00:00:00.0000000|25.73633441|
|Line2|2021-07-05T00:00:00.0000000|32.07489451|
|Line2|2021-07-12T00:00:00.0000000|21.69795038|
|Line2|2021-07-19T00:00:00.0000000|40.61744966|
|Line2|2021-07-26T00:00:00.0000000|37.43225806|
|Line2|2021-08-02T00:00:00.0000000|37.1459695|
|Line2|2021-08-09T00:00:00.0000000|16.46602972|
|DAT1|2021-06-28T00:00:00.0000000|12.15075669|
|DAT1|2021-07-05T00:00:00.0000000|12.95340711|
|DAT1|2021-07-12T00:00:00.0000000|12.68958704|
|DAT1|2021-07-19T00:00:00.0000000|12.99383503|
|DAT1|2021-07-26T00:00:00.0000000|13.11240762|
|DAT1|2021-08-02T00:00:00.0000000|12.64057632|
|DAT1|2021-08-09T00:00:00.0000000|13.91897614|
|Line3|2021-06-28T00:00:00.0000000|24.40082738|
|Line3|2021-07-05T00:00:00.0000000|26.9215045|
|Line3|2021-07-12T00:00:00.0000000|33.48339249|
|Line3|2021-07-19T00:00:00.0000000|35.30443195|
|Line3|2021-07-26T00:00:00.0000000|24.10078348|
|Line3|2021-08-02T00:00:00.0000000|24.38986198|
|Line3|2021-08-09T00:00:00.0000000|23.01571942|
|Line4|2021-06-28T00:00:00.0000000|18.31940786|
|Line4|2021-07-05T00:00:00.0000000|62.58973029|
|Line4|2021-07-12T00:00:00.0000000|46.85274308|
|Line4|2021-07-19T00:00:00.0000000|63.04209229|
|Line4|2021-07-26T00:00:00.0000000|68.0345323|
|Line4|2021-08-02T00:00:00.0000000|43.31426733|
|Line4|2021-08-09T00:00:00.0000000|40.91068764|
|Line5|2021-06-28T00:00:00.0000000|17.79028884|
|Line5|2021-07-05T00:00:00.0000000|19.16239758|
|Line5|2021-07-12T00:00:00.0000000|32.03355982|
|Line5|2021-07-19T00:00:00.0000000|39.62079781|
|Line5|2021-07-26T00:00:00.0000000|52.00414891|
|Line5|2021-08-02T00:00:00.0000000|18.76148808|
|Line5|2021-08-09T00:00:00.0000000|18.67315362|
|Line6|2021-06-28T00:00:00.0000000|3.32231405|
|Line6|2021-07-05T00:00:00.0000000|4.040229885|
|Line6|2021-07-12T00:00:00.0000000|6.827956989|
|Line6|2021-07-19T00:00:00.0000000|3.918439716|
|Line6|2021-07-26T00:00:00.0000000|13.4648318|
|Line6|2021-08-02T00:00:00.0000000|2.890804598|
|Line6|2021-08-09T00:00:00.0000000|4.9669967|
|Line7|2021-06-28T00:00:00.0000000|8.460313167|
|Line7|2021-07-05T00:00:00.0000000|8.398530986|
|Line7|2021-07-12T00:00:00.0000000|4.141188904|
|Line7|2021-07-19T00:00:00.0000000|7.0440826|
|Line7|2021-07-26T00:00:00.0000000|7.515569879|
|Line7|2021-08-02T00:00:00.0000000|5.496871261|
|Line7|2021-08-09T00:00:00.0000000|6.168009966|
|Line8|2021-06-28T00:00:00.0000000|16.22420184|
|Line8|2021-07-05T00:00:00.0000000|17.24927069|
|Line8|2021-07-12T00:00:00.0000000|10.32094119|
|Line8|2021-07-19T00:00:00.0000000|35.20252499|
|Line8|2021-07-26T00:00:00.0000000|69.49003928|
|Line8|2021-08-02T00:00:00.0000000|53.48326518|
|Line8|2021-08-09T00:00:00.0000000|50.99181579|

Hi,

Could you explain in a bit more detail what it is you like to group together. Looking at the 'blue plot' and your data I can't see it.

PJ

I am sorry, I removed the original headings, and forgot to replace them with the place holders. The groupings are the Lines. i.e. line1, line2. I can get the grouping to work properly, but the actual y-axis graphing is incorrect and the date in the x axis is not displaying correctly.

but you have no distinguishing feature between what to facet on (multiple charts) vs internal group chart (dark vs light shade of bars)
if we assume that Line is the Plant mentioned in facet wrap, that may allow for faceting(i.e. multiple charts).
but how are the within bar colourings to be determined ?

I figured it out, I had to correct the class of the columns in the database. I was exporting from Power Bi and thought that it would export the columns properly, then I realized that it was just exporting the data as a CSV file.

Thanks for all the help

This topic was automatically closed 7 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.