With ggplot I´ve made a histogram with some values. I want to change the color of the highest bar, so that it makes the plot more legible.
library(ggplot2)
ggplot(df,
aes(as.Date(created_at), as.numeric(count))) +
geom_col(fill = 'cornflowerblue') +
theme_minimal(base_size = 10) +
xlab(NULL) + ylab(NULL) +
scale_x_date(date_labels = "%Y/%m/%d",date_breaks = "days",expand = c(0,0)) + #El espaciado por días
theme(axis.text.x=element_text(angle=90, vjust = 0.5))+#Cambiamos la posición del x
geom_text(aes(label = count, y = count+50), position = position_dodge(0.9),angle=90, vjust = 0.5,size=3)+
ggplot2::theme(
plot.title = ggplot2::element_text(face = "bold",colour = "black"))+
ggplot2::labs(
x = NULL, y = NULL, #Info en cada eje
title = "Tweets sobre el COVID-19 por día", #Texto
subtitle = ""
)
This may help you:
library(ggplot2)
library(dplyr)
data(mtcars)
count(mtcars, cyl) %>%
mutate(col=ifelse(n==max(n), "red","blue")) %>% # Add this line,
ggplot(aes(cyl, n, fill=as.factor(col))) +
geom_col() +
ylab("Frequency") +
scale_fill_identity() + # And this one to use the actual colours.
theme_minimal()
I have tried this, but does not work
covidtweets %>%
mutate(col=ifelse(count==max(count), "red","blue")) %>%
ggplot( aes(as.Date(created_at), as.numeric(count),fill=as.factor(col))) +
theme_minimal(base_size = 10) +
#geom_line(data = spain_deaths, aes(as.Date(time), as.numeric(cum_dead)), color= 'blue4', size=1.1)+
#geom_point(color="red")+
xlab(NULL) + ylab(NULL) +
scale_x_date(date_labels = "%Y/%m/%d",date_breaks = "days",expand = c(0,0)) + #El espaciado por días
theme(axis.text.x=element_text(angle=90, vjust = 0.5))+#Cambiamos la posición del x
geom_text(aes(label = count, y = count+50), position = position_dodge(0.9),angle=90, vjust = 0.5,size=3)+
ggplot2::theme(
plot.title = ggplot2::element_text(face = "bold",colour = "black"))+
ggplot2::labs(
x = NULL, y = NULL, #Info en cada eje
title = "Tweets sobre el COVID-19 por día", #Texto
subtitle = ""
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.