我正在使用时间使用调查数据来确定不同活动的时间安排。在我制作的情节下方
但是我发现很难理解和识别该图上的不同元素。例如,由于颜色,很难识别活动(例如,颜色几乎相似)。我希望这些活动具有不同的颜色或不同的标志,以使其易于识别
是否有更好的方法来表示此数据?非常感谢。
我正在使用的代码
plot<-ggplot(melted_Activities, aes(x = time,y = value,fill = variable)) + geom_col(stat = "identity", position="fill")
plot + labs(x="Time", y="Precentages", colour="Activties", fill="Activites")+theme(legend.position="right", axis.text.x = element_text(angle = 0, hjust = 0))+ annotate("rect", fill = "black", alpha = 0.3, xmin = c(73), xmax = c(97), ymin = -Inf, ymax = Inf) + scale_x_discrete(breaks = c( "04:00","05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00","13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00","22:00", "23:00", "00:00", "01:00", "02:00", "03:00"), expand = c(0,0)) + scale_y_continuous(expand = c(-0,0), labels = scales::percent)
在我的数据下面:
dput(head(melted_Activities,144))
structure(list(time = c("04:00", "04:10", "04:20", "04:30", "04:40",
"04:50", "05:00", "05:10", "05:20", "05:30", "05:40", "05:50",
"06:00", "06:10", "06:20", "06:30", "06:40", "06:50", "07:00",
"07:10", "07:20", "07:30", "07:40", "07:50", "08:00", "08:10",
"08:20", "08:30", "08:40", "08:50", "09:00", "09:10", "09:20",
"09:30", "09:40", "09:50", "10:00", "10:10", "10:20", "10:30",
"10:40", "10:50", "11:00", "11:10", "11:20", "11:30", "11:40",
"11:50", "12:00", "12:10", "12:20", "12:30", "12:40", "12:50",
"13:00", "13:10", "13:20", "13:30", "13:40", "13:50", "14:00",
"14:10", "14:20", "14:30", "14:40", "14:50", "15:00", "15:10",
"15:20", "15:30", "15:40", "15:50", "16:00", "16:10", "16:20",
"16:30", "16:40", "16:50", "17:00", "17:10", "17:20", "17:30",
"17:40", "17:50", "18:00", "18:10", "18:20", "18:30", "18:40",
"18:50", "19:00", "19:10", "19:20", "19:30", "19:40", "19:50",
"20:00", "20:10", "20:20", "20:30", "20:40", "20:50", "21:00",
"21:10", "21:20", "21:30", "21:40", "21:50", "22:00", "22:10",
"22:20", "22:30", "22:40", "22:50", "23:00", "23:10", "23:20",
"23:30", "23:40", "23:50", "00:00", "00:10", "00:20", "00:30",
"00:40", "00:50", "01:00", "01:10", "01:20", "01:30", "01:40",
"01:50", "02:00", "02:10", "02:20", "02:30", "02:40", "02:50",
"03:00", "03:10", "03:20", "03:30", "03:40", "03:50"), variable = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Personal care",
"Sleep", "Eating", "Other personal care", "Employment", "Main job",
"Second job", "Activites related to employment", "Study", "School or University",
"Free time study", "House and family care", "Food management",
"Household maintenance", "Making care for textiles", "Gardening and pet care",
"Construction and repairs", "Shopping and services", "Household management",
"Childcare of own household member", "Help to an adult household member",
"Volunteer work and meeting", "Organisational work", "Informal help to others",
"Participatory activties", "Social care", "Social life", "Entertainment and culture",
"Resting", "Sport and outdoor activities", "Physical exercise",
"Productive exercise", "Sportsrelated activities", "Hobbies, games and computing",
"Arts and hobbies", "Computing", "PC Games", "Mass media", "Reading",
"Tv and video", "Radio and music", "Travel and unspecified time use",
"Travel by purpose", "Punctuating activity"), class = "factor"),
value = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), row.names = c(NA,
144L), class = "data.frame")
答案 0 :(得分:2)
在我的comment之后,我在想这样的事情。
time <- melted_Activities$time
time <- as.POSIXct(paste(Sys.Date(), time), format = "%Y-%m-%d %H:%M")
melted_Activities$period <- cut(time, "6 hour")
melted_Activities$period <- format(melted_Activities$period, "%H:%M")
然后在period
的6个小时内完成任务。
p <- ggplot(melted_Activities, aes(x = time,y = value, fill = variable)) +
geom_col(position = "fill") +
facet_wrap(~ period)
或者是折线图。
p <- ggplot(melted_Activities, aes(x = time,y = value, colour = variable)) +
geom_line() +
facet_wrap(~ period)