Я пытаюсь построить помеченный барплот с помощью ggplot2 с положительными и отрицательными столбцами.
indegree<- c("Volunteer work and meeting (1 code)", "TV and Video (8 codes)", "Travel by purpose (30 codes)", "Travel and unspecified time use (1 code)", "Study (1 code)",
"Sports related activites (3 codes)", "Sports and outdoor activities (1 code)","Social life (6 codes)", "Social care(1 code)", "Shopping and services (11 codes)",
"Second Job (2 codes)","School or University (4 codes)", "Resting-Time out (1 code)", "Reading (4 codes)", "Radio and Music (6 codes)", "Games (9 codes)",
"Physical exercise (20 codes)","Personal care (1 cdoe)", "Participatory activities (4 codes)","Other personal care (3 codes)","Organisational work (4 codes)",
"Mass media (1 code)", "Making care for textiles (5 codes)","Main job (3 codes)", "Sleep (3 codes)", "Informal help to other households (23 codes)", "Household upkeep (7 codes)",
"Household management (10 codes)", "Household and family care (1 code)", "Hobbies, games and computing (1 code)", "Help to an adult household member",
"Gardening and pet care (5 codes)", "Free time study (1 code)", "Food Management (5 codes)", "Entertainment and culture (25 codes)", "Employment(1 code)",
"Eating (1 code)", "Construction and repairs (8 codes)", "Computing (10 codes)","Childcare of own household members (8 codes)", "Arts and hobbies (14 codes)",
"Activities related to employment (5 codes)","Punctuating activity (eg. Unspecified time use, 8 codes)")
Создание значений неопределенности
indegreevalues <- as.numeric(c(3, 35, 37, 26, 3, 5, 4, 36, 2, 29, 4, 23, 31, 29, 23, 28, 33, 5, 22, 37, 15, 12, 28, 28, 32, 25, 37, 26,
22,4,16,30,11,34,22,5,35,26,33,26,22,16, 35))
df.1 <- data.frame(indegree, indegreevalues) #created a data frame
Создание кадра данных 2
outdegree<- c("Volunteer work and meeting (1 code)", "TV and Video (8 codes)", "Travel by purpose (30 codes)", "Travel and unspecified time use (1 code)", "Study (1 code)",
"Sports related activites (3 codes)", "Sports and outdoor activities (1 code)","Social life (6 codes)", "Social care(1 code)", "Shopping and services (11 codes)",
"Second Job (2 codes)","School or University (4 codes)", "Resting-Time out (1 code)", "Reading (4 codes)", "Radio and Music (6 codes)", "Games (9 codes)",
"Physical exercise (20 codes)","Personal care (1 cdoe)", "Participatory activities (4 codes)","Other personal care (3 codes)","Organisational work (4 codes)",
"Mass media (1 code)", "Making care for textiles (5 codes)","Main job (3 codes)", "Sleep (3 codes)", "Informal help to other households (23 codes)", "Household upkeep (7 codes)",
"Household management (10 codes)", "Household and family care (1 code)", "Hobbies, games and computing (1 code)", "Help to an adult household member",
"Gardening and pet care (5 codes)", "Free time study (1 code)", "Food Management (5 codes)", "Entertainment and culture (25 codes)", "Employment(1 code)",
"Eating (1 code)", "Construction and repairs (8 codes)", "Computing (10 codes)","Childcare of own household members (8 codes)", "Arts and hobbies (14 codes)",
"Activities related to employment (5 codes)","Punctuating activity (eg. Unspecified time use, 8 codes)")
Создание конечной степени
outdegreevalues<- as.numeric(c(30, 25, 5, 28, 22, 12, 35, 35, 30, 32, 25, 16, 34, 4, 3, 1, 24, 34, 28, 32, 19, 8, 23, 21, 30, 4, 30, 35,
35,23,23,30,27,25,39,39,20,29,4,12,4,15, 5))
Создание нового фрейма данных
df.2 <- data.frame(outdegree, outdegreevalues) #created second df
df <- merge(df.1,df.2,by.x = "indegree",by.y = "outdegree")
Построение объединенных фреймов данных
p<-ggplot(df) +
geom_bar(aes(x=indegree,y=indegreevalues),fill="blue",stat="identity",position="dodge") +
geom_bar(aes(x=indegree,y=-outdegreevalues),fill="red",stat="identity",position="dodge")+
labs(x="Activities", y="Count", fill="") +
theme(legend.position = "bottom", axis.text.x = element_text(angle = 90, hjust = 1))
Однако у меня возникла проблема при построениилегенда.Не могли бы вы помочь мне, пожалуйста, чтобы построить легенду
введите описание изображения здесь