0
我想創建一個具有多個列中的不同變量的R條形圖,全部在一個圖表中。我只能做一個2x2的情節用下面的代碼:具有多個列中的不同變量的R條形圖
barplot(table(y = cut$Gender,x = cut$Education))
即使如此,性別被堆放在教育的頂部。
我的樣本數據集:
structure(list(Gender = c("Male", "Male", "Male", "Male", "Male",
"Male", "Male", "Male", "Female", "Male", "Male", "Male", "Male",
"Female", "Male", "Female", "Male", "Male", "Male", "Male"),
Age = c("45-54 yrs", "35-44 yrs", "25-34 yrs", "25-34 yrs",
"25-34 yrs", "45-54 yrs", "25-34 yrs", "25-34 yrs", "25-34 yrs",
"35-44 yrs", "18-24 yrs", "25-34 yrs", "25-34 yrs", "55-64 yrs",
"35-44 yrs", "35-44 yrs", "35-44 yrs", "45-54 yrs", "35-44 yrs",
"45-54 yrs"), Employment = c("Civil servant", "Private sector",
"Private sector", "Private sector", "Trader", "Civil servant",
"Private sector", "Private sector", "Private sector", "Civil servant",
"Student", "Student", "Civil servant", "Retired", "Self-employed",
"Private sector", "Civil servant", "Civil servant", "Private sector",
"Private sector"), Marriage = c("Married", "Married", "Married",
"Married", "Single, never married", "Married", "Married",
"Married", "Married", "Married", "Single, never married",
"Single, never married", "Married", "Married", "Married",
"Married", "Married", "Married", "Married", "Married"), Education = c("Advanced degree",
"Advanced degree", "Bachelor's degree", "Bachelor's degree",
"Secondary education", "Advanced degree", "Bachelor's degree",
"Bachelor's degree", "Secondary education", "Secondary education",
"Secondary education", "Secondary education", "Advanced degree",
"Bachelor's degree", "Basic education", "Advanced degree",
"Advanced degree", "Advanced degree", "Advanced degree",
"Advanced degree"), Residence = c("Ashanti", "Ashanti", "Ashanti",
"Ashanti", "Ashanti", "Brong-Ahafo", "Brong-Ahafo", "Brong-Ahafo",
"Brong-Ahafo", "Brong-Ahafo", "Brong-Ahafo", "Brong-Ahafo",
"Central", "Central", "Eastern", "Greater Accra", "Greater Accra",
"Greater Accra", "Greater Accra", "Greater Accra"), Experience = c("Never",
"Never", "Never", "Never", "Never", "Never", "Never", "Never",
"Never", "Never", "Never", "Never", "Never", "Never", "Never",
"Never", "Never", "Never", "Never", "Never")), .Names = c("Gender",
"Age", "Employment", "Marriage", "Education", "Residence", "Experience"
), row.names = c(NA, 20L), class = "data.frame")
謝謝變異甚至添加一個條件換行符。有沒有辦法用百分比替換count_frequency(0到20)(如0-100%)。 – Masssly
只需添加'scale_y_continuous(labels = c(「0%」,「25%」,「50%」,「75%」,「100%」),breaks = c(0,5,10,15,20) )'。還有其他方法,但我相信這在目前的例子中是最簡單的 – missuse