0

I am new to R language, and i'm trying to learn how to create a visualization for the data frame of my students degrees. My table is somewhat like this, but bigger:

names grade_one grade_two grade_three grade_four
Ana 5.7 6.3 4.0 5.0
Beth 3.5 5.0 7.0 8.0
Rick 9.0 9.0 9.0 9.0
Zoe 8.0 8.7 8.0 9.0

etc

I want to put 'names' on y axis, and the grades 'one','two','three' and so on x axis, and thought about making a line visualization showing the evolution of the students. I would appreciate too if i can give random colors to each name of my 12 students of this classroom to improve viz.

I tried this one and other attempts without success:

ggplot(data=notas)+geom_line(mapping=aes(x=grade_one+grade_two,y=names))

I can do this on sheets but would be great learning how to make on RStudio

Would appreciate any help!

Edit:

I already saw the topic "how-to-create-a-ggplot-bar-chart-with-multiple-columns-of-data-for-y"

Maybe because i'm new to R, idk, i think its slightly different. I want to make a line chart, which each student has its own line on the chart, going from left to right, giving them random colors. I see now that values should be on y axis, the four grades on x axis; and each line showing their performance are labelled on the right side of the chart. But if it's a similar code as the other topic, idk how to adapt.

The ideia behind the line chart in this case, its to compare the evolution of the students between themselves, like "oh, look how at this point the student A exceeded the student B". The bars chart would reproduce more a isolated view of each one, which its not what i seek. Lines crossing each other would be ideal.

Also its not a school homework. I'm the teacher and i'm want to teach them graphical analysis and of course i'm practicing R too.

Daniel C
  • 1
  • 2
  • 1
    If this is a school assignment / homework, please read [How do I ask homework questions?](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions) and edit your post accordingly. If it isn't homework, I suggest you investigate the `pivot_longer()` function from the [tidyr package](https://tidyr.tidyverse.org/reference/pivot_longer.html) then plot the 'pivoted' data with `ggplot(aes(x = grade, y = value, color = names, group = names)) + geom_line()` and go from there – jared_mamrot Feb 24 '23 at 05:20
  • 1
    fyi `coord_flip` largely unnecessary since Mar 2020's ggplot2 3.3.0: https://www.tidyverse.org/blog/2020/03/ggplot2-3-3-0/#bi-directional-geoms-and-stats – Jon Spring Feb 24 '23 at 05:53
  • 1
    Agree that reshaping to long format is first step. Then barplot with student and year as x categories, then coord_flip to make the bars horizontal. – IRTFM Feb 24 '23 at 05:58

0 Answers0