Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
breakoutModewide
breakoutWidth760
mtcars_sub <- head(mtcars)
library(tidyverse)
mtcars_long <- mtcars_sub %>%
      rownames_to_column(var = "model") %>% # Convert row names (car models) to a column
      pivot_longer(
        cols = -c(mpg, model), # Select all columns except 'mpg, model' to pivot
        names_to = "variable", # New column for the original column names
        values_to = "value" # New column for the values from the original columns
      )

...

Code Block
breakoutModewide
breakoutWidth760
library(data.table)
mtcars_sub$model <- rownames(mtcars_sub)
mtcars_long <- melt(
  data.table(mtcars_sub),  
  id.vars = c("model"), 
  variable.name = 'desigvariable', 
  measure.name =  colnames(mtcars_sub)[-c(length(colnames(mtcars_sub)))] != 'mpg'] #additional methods
  )
Info

ggplot2 is very powerful

...