Bar chart not coming in the desirable way

I have a data for tracking attendance of teachers. In the sample data I have given the variable attendance. 1 means attended and 2 means absent. Now I need to get a bar chart where I get the Instructors name on the X-axis and the average attendance % on the Y-axis with different bars showing different weeks (like doing position_dodge. How can I get such a bar chart?

             ~master,  ~teacher, ~week, ~attendance,
        "Madhumathi", "Vinayak",    1L,          2L,
             "Nagma",  "Ganesh",    1L,          1L,
              "Anil",  "Nithin",    1L,          1L,
        "Madhumathi", "Vinayak",    1L,          1L,
             "Nagma",  "Ganesh",    1L,          2L,
              "Anil",  "Nithin",    1L,          2L,
        "Madhumathi", "Vinayak",    1L,          2L,
             "Nagma",  "Ganesh",    1L,          1L,
              "Anil",  "Nithin",    1L,          2L,
        "Madhumathi", "Vinayak",    2L,          2L,
             "Nagma",  "Ganesh",    2L,          2L,
              "Anil",  "Nithin",    2L,          2L,
        "Madhumathi", "Vinayak",    2L,          1L,
             "Nagma",  "Ganesh",    2L,          2L,
              "Anil",  "Nithin",    2L,          2L,
        "Madhumathi", "Vinayak",    2L,          1L,
             "Nagma",  "Ganesh",    2L,          1L,
              "Anil",  "Nithin",    2L,          2L

What have you tried so far? I only see one entry per person per week. Is this because it's just demo data?
So you want to to show all the weeks as bars, and then additionally on top of that the average (e.g. as line)?

The bars are easy, or?

I want the bar chart with the name of teachers on the X-axis and and attendance on Y-axis. Ya only one entry is there because this is a sample data. The attendance is required to be taken every day of the week. So 5 entries per teacher per week will appear.

I have edited the original post to make it clear.

Well in this case you could start by summarising the data, so calculating the average of the attendance per week:

data_summarised = data %>% 
  group_by(master, teacher) %>% 
  summarise(attendance = mean(attendance),
            .groups = "keep")

Also (if possible) i would encode it differentially, saying absent = 0, present =1, then the attendance column is basically a percent scale, (close to) 1 means always there, close to 0 means often absent.

If I have 5 measurements of some subject then I can either
calculate the average of the 5 and plot that thing (an average)
not involve averaging and plot the 5 things.

Your post reads like it expects to do both; I'm trying to imagine that; would it be plotting therefore 6 things per subject; the 5 actual values and the average value of the 5 ? or ... ?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.