0

It is longitudinal data; ID wise values are repeating 4 times in every tick of 20 steps. Then this experiments repeats. For the datafarme below I want bins based for every tick time steps for the categories of land based on the values of X. Bins can be 3 for every time interval for land type (Small, medium and large) each. I want to see timeline of bins of X based on categories of Land. Any help will be appreciated. I have added possibly a picture of how data may look like for ggplot and plot as bins or dots may look like as in picture.

   Seed(123)
ID = 1:5
Time = rep (c(1,2,3,4,5), each = 20)
Type = 1:25
data <- data.frame( IDn = rep(ID,20), Time,  Land = rep(Type, 40), y = rnorm(100,0,1), x = runif(100,0,1))
data$Land= ifelse (data$Land > 15,"large farmers", ifelse(data$Land <=5, "small farmers", "medium-farmers"))

enter image description here

enter image description here

Edit: Question for labeling the faceting variable and dot plots.

enter image description here

Sadaf
  • 163
  • 7
  • @Ronak shah; I have tried my best to reduce the data and also added that how possibly data and graph may look like. or another which may represent development over ticks. Thanks – Sadaf May 23 '21 at 08:39

1 Answers1

1

Maybe something like this would help -

library(dplyr)
library(ggplot2)

data %>%
  group_by(Time, Land) %>%
  mutate(x = cut(x, c(0, 0.25, 0.75, 1))) %>%
  ungroup %>%
  count(Time, Land, x) %>%
  ggplot() + aes(Time, n, fill = Land) + geom_col(position = 'dodge')
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Thanks @Ronak Shah. This solved my problem. What to be changed if bar of bins are to be replaced with dots? and if legend for X to be added as bar shows the count but not the categories of x we have made. that what is this count for! – Sadaf May 24 '21 at 19:38
  • I have added facet_grid(~x, nrow(2)). But can't figure out that how this will be labled on the graph that facet shows values of X. Can you please help? – Sadaf May 25 '21 at 12:11
  • Sorry, your question is not clear to me. Do you need `ggplot() + aes(x, n, fill = Land) + geom_col(position = 'dodge')` ? keeping `x` on X-axis ? – Ronak Shah May 25 '21 at 12:21
  • I have just edit and shared graph. I hope now my question is making sense! Can you please see that @Ronak. – Sadaf May 25 '21 at 15:07
  • Hi, I don't think this is related to your original question. Please ask that as a new question so that this post focusses only on one question and will not confuse future readers. – Ronak Shah May 25 '21 at 23:13