根据列更改标签的字体粗细

时间:2015-07-13 21:15:15

标签: python ggplot2 data-visualization

我使用ggplot为Python生成了以下图表。 x轴表示5月份的天数。

enter image description here

有没有办法突出周末的日子?例如,只要列weekend == 1

,就使标签变为粗体

我尝试在aestheme内使用geom_text无效。

1 个答案:

答案 0 :(得分:1)

这样的事情会起作用吗? (以下代码)

bold weekend in ggplot2

by_day <- data.frame(
  X=0:6,
  weekday=0:6,
  variable="Number_of_tweets",
  value=c(5820,6965,7415,6800,5819,1753,1137))


# install.packages("ggplot2", dependencies = TRUE)
library(ggplot2)

p <- ggplot(data=by_day, aes(x=weekday, y=value)) + 
            geom_bar(stat = "identity") +
            scale_x_continuous(breaks=0:6,
            labels=c("Mon","Tue","Wed","Thu","Fri","Sat","Sun"))

p + theme(axis.text=element_text(face=rep(c("plain", "bold"), c(5,2))))
相关问题