0

I want to do a barplot of this dataset

           df <- data.frame(Modelos=c("Model 1", "Model 2"),            
          MSE_test=c(123293931,23231231),MSE_train=c(100001,2292894))

I want to do a barplot of this to compare the values of each model in train and test. I think on that code but this doesn't do what I want.

           ggplot(df, aes(x=Modelos,y=MSE_test, fill = MSE_train)) + 
          geom_bar(position = "dodge")

I want each Model in the x axis and for each model one bar to test and the other to train. I hope to be clear.

1 Answer 1

1

You need to reshape the data first with reshape2 or tidyverse packages:

library(reshape2)

df <- df %>% 
    melt(id = "Modelos")

or

library(tidyverse)

df <- df %>%
    gather(variable, value, - Modelos)

then plot:

 ggplot(df, aes(Modelos, value)) + 
    geom_bar(aes(fill = variable),stat = "identity", position = "dodge") +
    scale_y_log10()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.