How to chart profiles in R?

Asked

Viewed 1,572 times

4

I’m trying to create a profile chart for this data frame that I titled "Femi":

inserir a descrição da imagem aqui

This is the data code:

structure(list(oito = c(21, 21, 20.5, 23.5, 21.5, 20, 21.5, 23, 
20, 16.5, 24.5), dez = c(20, 21.5, 24, 24.5, 23, 21, 22.5, 23, 
21, 19, 25), doze = c(21.5, 24, 24.5, 25, 22.5, 21, 23, 23.5, 
22, 19, 28), catorze = c(23, 25.5, 26, 26.5, 23.5, 22.5, 25, 
24, 21.5, 19.5, 28)), .Names = c("oito", "dez", "doze", "catorze"
), class = "data.frame", row.names = c(NA, -11L))

Each observation is a child, who was observed at 8, 10, 12 and 14 years of age.

I managed to make the following chart: inserir a descrição da imagem aqui

Now I need to insert lines that connect each observation made on the same individual, thus tracing a profile of each individual as their age changes.

  • 2

    Cloves, instead of an image, post your data using the command dput. The code you used is also recommended, although I don’t think it will be necessary in this case.

1 answer

3


Using the dplyr, tidyr and ggplot2 you can do so:

library(dplyr)
library(tidyr)
library(ggplot2)
dados %>%
  mutate(id = row_number()) %>%
  gather(idade, distancia, -id) %>%
  mutate(idade = factor(idade, levels = c("oito", "dez", "doze", "catorze"))) %>%
  ggplot(aes(x = idade, y = distancia, group = id)) + geom_line() + geom_point()

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.