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

2024-04-25 17:08:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用ggplot for Python生成了以下图形。x轴代表五月的几天。你知道吗

enter image description here

有没有办法突出周末的几天?例如,在列weekend == 1时将标签加粗?你知道吗

我试过在themegeom_text内部使用aes,但没有效果。你知道吗


Tags: text图形for代表标签themeaes效果
1条回答
网友
1楼 · 发布于 2024-04-25 17:08:57

你喜欢这个工作吗?(代码如下)

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))))

相关问题 更多 >