柱狀圖4之多分類變量百分條圖2

知識點

  • 通過做負(fù)高度柱子和背景色柱子做出最坐邊的灰色柱子
  • 通過正負(fù)柱子做出藍(lán)色和紅色柱子
barcharts_multiple_all_2
pdf_file <- "barcharts_multiple_all_2.pdf"
cairo_pdf(bg="grey98", pdf_file, width=13,height=10.5)

# 定義標(biāo)簽名稱
myC_v159 <- "A working mother can establish just as warm and\nsecure an environment as a non-working mother"
myC_v160 <- "A pre-school child is likely to suffer if\nhis or her mother is working"
myC_v161 <- "A job is alright, but what most women\nreally want is a home and children"
myC_v162 <- "Being a housewife is just as fulfilling as\nworking"
myC_v163 <- "Having a job is the best way for a woman\nto be independent"
myC_v164 <- "Both the husband and wife should contribute\nto the family income"
myC_v165 <- "In general, fathers are as well suited to\nlook after their children as women"
myC_v166 <- "Men should take as much responsibility\nas women for their household and children"
mynames <- c(myC_v165, myC_v164, myC_v163, myC_v162, myC_v161, 
    myC_v160, myC_v159)
myresponses <- c("n.a./don’t know", "agree strongly", "agree", 
    "disagree", "disagree strongly")

add_fonts("lato")
par(omi = c(0.25, 0.75, 1, 0.75), mai = c(1.8, 3.75, 0.25, 0), 
    lheight = 1.15, family = "Lato Light", las = 1)

library(RColorBrewer)
myC1 <- rgb(0, 208, 226, maxColorValue = 255)
myC2 <- rgb(109, 221, 225, maxColorValue = 255)
myC3 <- rgb(255, 138, 238, maxColorValue = 255)
myC4 <- rgb(255, 0, 210, maxColorValue = 255)
colours <- c("grey", myC1, myC2, myC3, myC4)

# 構(gòu)造數(shù)據(jù)
col_1 <- c(2, 5, 3, 6, 2, 7, 8)
col_2 <- c(20, 15, 14, 15, 12, 30, 10)
col_3 <- c(30, 20, 10, 13, 26, 32, 20)
col_4 <- c(20, 34, 30, 25, 30, 20, 16)
col_5 <- rep(100, 7) - col_1 - col_2 - col_3 - col_4
z <- cbind(col_1, col_2, col_3, col_4, col_5)
myData0 <- cbind(z[, 1], z[, 2], z[, 3], z[, 4], z[, 5])
myData1 <- t(myData0)

# 添加柱子
barplot(-rep(100, 7), names.arg = mynames, cex.names = 1.1, horiz = T, 
    border = par("bg"), xlim = c(-100, 70), col = colours[1], 
    axes = F)
barplot(-(100 - myData1[1, ]), names.arg = mynames, cex.names = 1.1, 
    horiz = T, border = par("bg"), xlim = c(-100, 70), col = par("bg"), 
    axes = F, add = T)
barplot(-myData1[3:2, ], names.arg = mynames, cex.names = 1.1, 
    horiz = T, border = NA, xlim = c(-100, 70), col = colours[3:2], 
    axes = F, add = T)
barplot(myData1[4:5, ], names.arg = mynames, cex.names = 1.1, 
    horiz = T, border = NA, xlim = c(-100, 70), col = colours[4:5], 
    axes = F, add = T)

# 添加線段
arrows(0, -0.1, 0, 8.6, lwd = 2.5, length = 0, xpd = T, col = "skyblue3")

# 添加圖例
px <- c(-98, -87, -41, 15, 65)
tx <- c(-105, -60, -26, 8, 60)
y <- rep(-1, 5)
points(px, y, pch = 15, cex = 4, col = colours, xpd = T)
text(tx, y, myresponses, adj = 1, xpd = T, font = 3)

# 添加x軸標(biāo)簽
mtext(c(80, 60, 40, 20, 0, 20, 40, 60), at = c(-80, -60, -40, 
    -20, 0, 20, 40, 60), 1, line = 0, cex = 0.95)

# 添加標(biāo)題
mtext("It is often said that attitudes towards gender roles are changing", 
    3, line = 2.2, adj = 0, cex = 1.8, outer = T, family = "Lato Black")
mtext("All values in percent", 3, line = 1, adj = 1, cex = 0.95, 
    font = 3)
mtext("Source: European Values Study 2008 Germany, ZA4753. www.gesis.org. Design: Stefan Fichtel, ixtract", 
    1, line = 5.2, adj = 1, cex = 0.95, font = 3)
mtext("N=2,075", 3, line = 1, adj = 0, cex = 1.15, family = "Lato Regular", 
    font = 3)
dev.off()
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末邓夕,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子恕洲,更是在濱河造成了極大的恐慌来涨,老刑警劉巖图焰,帶你破解...
    沈念sama閱讀 218,607評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異蹦掐,居然都是意外死亡技羔,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,239評論 3 395
  • 文/潘曉璐 我一進(jìn)店門笤闯,熙熙樓的掌柜王于貴愁眉苦臉地迎上來堕阔,“玉大人棍厂,你說我怎么就攤上這事颗味。” “怎么了牺弹?”我有些...
    開封第一講書人閱讀 164,960評論 0 355
  • 文/不壞的土叔 我叫張陵浦马,是天一觀的道長。 經(jīng)常有香客問我张漂,道長晶默,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,750評論 1 294
  • 正文 為了忘掉前任航攒,我火速辦了婚禮磺陡,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘漠畜。我一直安慰自己币他,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,764評論 6 392
  • 文/花漫 我一把揭開白布憔狞。 她就那樣靜靜地躺著蝴悉,像睡著了一般。 火紅的嫁衣襯著肌膚如雪瘾敢。 梳的紋絲不亂的頭發(fā)上拍冠,一...
    開封第一講書人閱讀 51,604評論 1 305
  • 那天尿这,我揣著相機(jī)與錄音,去河邊找鬼庆杜。 笑死射众,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的欣福。 我是一名探鬼主播责球,決...
    沈念sama閱讀 40,347評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼拓劝!你這毒婦竟也來了雏逾?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,253評論 0 276
  • 序言:老撾萬榮一對情侶失蹤郑临,失蹤者是張志新(化名)和其女友劉穎栖博,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體厢洞,經(jīng)...
    沈念sama閱讀 45,702評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡仇让,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,893評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了躺翻。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片丧叽。...
    茶點故事閱讀 40,015評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖公你,靈堂內(nèi)的尸體忽然破棺而出踊淳,到底是詐尸還是另有隱情,我是刑警寧澤陕靠,帶...
    沈念sama閱讀 35,734評論 5 346
  • 正文 年R本政府宣布迂尝,位于F島的核電站,受9級特大地震影響剪芥,放射性物質(zhì)發(fā)生泄漏垄开。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,352評論 3 330
  • 文/蒙蒙 一税肪、第九天 我趴在偏房一處隱蔽的房頂上張望溉躲。 院中可真熱鬧,春花似錦益兄、人聲如沸锻梳。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,934評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽唱蒸。三九已至,卻和暖如春灸叼,著一層夾襖步出監(jiān)牢的瞬間神汹,已是汗流浹背庆捺。 一陣腳步聲響...
    開封第一講書人閱讀 33,052評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留屁魏,地道東北人滔以。 一個月前我還...
    沈念sama閱讀 48,216評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像氓拼,于是被迫代替她去往敵國和親你画。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,969評論 2 355

推薦閱讀更多精彩內(nèi)容