3

I want to make some line plot divided by models.

Here is my dataframe code:

Jumping = c(0.99,0.97,0.99,1,1)
Lunge = c(0.89,0.99,0.99 ,1,1)
Squat = c(0.97,0.99,0.99,1,1)
Stand = c(0.95,0.99, 1,1,1)
Standing_abs = c(1,0.97,0.99,0.99,0.97)
action = c("Jumping","Lunge","Squat","Stand","Standing_abs")
model = c("Knn","Dt","DNN","RF","rbf_SVM")

result = data.frame(Jumping,Lunge,Squat,Stand,Standing_abs,row.names = model)
result

and result >

        Jumping Lunge Squat Stand Standing_abs
Knn        0.29  0.39  0.97  0.65         0.60
Dt         0.97  0.69  0.88  0.99         0.97
DNN        0.99  0.79  0.49  1.00         0.59
RF         1.00  0.77  1.00  0.91         0.39
rbf_SVM    1.00  1.00  1.00  0.58         0.97

But There is some problem. The result I wanted was like..

enter image description here

How can I make line plot like image seperated by models? Have a nice day!

1
  • 2
    You need to convert your data into long format first. You need columns Model, Activity, Value and 25 rows. Commented Oct 15, 2020 at 10:24

2 Answers 2

4
require(rtidy)
require(ggplot2)

result %>% 
  add_rownames("model") %>% 
  gather("Activity","value",-model) %>% 
  ggplot(aes(x=Activity,y=value,color=model,group=model)) + geom_line()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

3

You could transpose the data and use pivot_longer to create rows for each model.
Try:

library(tidyverse)
data <- t(result) %>% as.data.frame %>% 
                      rownames_to_column() %>%
                      pivot_longer(cols = rownames(result),names_to = "model")

ggplot(data) + geom_line(aes(group = model, x=rowname,y=value,color=model)) + xlab('Exercice')

enter image description here

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.