Last answered:

07 Apr 2023

Posted on:

03 Apr 2023


Resolved: Stacked Area Chart - Base R

This is more of a comment than a question...

1.  You don't need to load the dplyr package to remove a column - in this case column 5 or variable "Other."

Just use the Subset command in base R and keep it simple.

temp <- df_engine_types[ , -5]      # This removes column 5.

2.  In addition I wouldn't use the reshape2 package to Combine "Gas", "Petrol" and "Diesel" categories into one column.  Keep it simple and use the base R reshape.

  tempLong <- reshape(temp, 
          direction = "long",
          varying = c("Gas", "Petrol", "Diesel"),    # columns that will be stacked into one column
          v.names = "amount",                             # Name of the column with fuel values.
          timevar = "fuel",                                   # Name of column for the various fuels
          times = c("Gas", "Petrol", "Diesel"),   # the fuels for the "fuel" variable.
          idvar = "Year"                                    # Your id column


# To Remove the row names (if needed) use...

 rownames(tempLong) <- c()         # Remove row names


My $0.02

1 answers ( 1 marked as helpful)
Posted on:

07 Apr 2023


Hi T. Serghides, 

thanks for reaching out and for your comments, I'll consider adding an alternative script with your suggestions to the course materials. 

Happy learning!


365 Eli

Submit an answer