我有一个像这样的数据帧(freqOvertimeHourlyData):
HOURS INTERVAL BARCOLOR
1 147 16-17 "green"
2 150 17-18 "green"
3 144 18-19 "blue"
4 149 19-20 "red"
5 139 20-21 "red"
6 101 21-22 "red"
Run Code Online (Sandbox Code Playgroud)
有没有办法geom_bar根据BARCOLOR栏中的值为条形着色?我目前的情节是这样的:
ggplot(freqOvertimeHourlyData, aes(x=INTERVAL, y=HOURS))+
geom_histogram(stat="identity")+
theme(legend.position="none")
Run Code Online (Sandbox Code Playgroud)
如果您希望使用原始值而不缩放,以获得美观,则scale_identity可以使用.使用来自@Sandy Muspratt的答案的"DF":
ggplot(DF, aes(x = INTERVAL, y = HOURS, fill = BARCOLOR))+
geom_bar(stat = "identity")+
theme(legend.position = "none") +
scale_fill_identity()
Run Code Online (Sandbox Code Playgroud)
