The text printed using geom_text in my circular bar plot is not acceptable and the resolution is very low. Given the label is too long, I wanted to fold them up to make it short. However, I did not find any means to do so. How can I make it?
library(tidyverse)
df2 <- data.frame (No=seq(1,6),
DrugID =
c('glyphosate','triclosan','alfacalcidol','tertracyline',
"3,3',5,5'-Tetraiodothyroacetic Acid",
'Calcitriol'),
Score = c('0.98','0.93','0.95','0.98','0.78','0.86'))
label_data <- df2
number_of_bar <- nrow(label_data)
angle <- 90 - 360*(label_data$No-0.5) /number_of_bar
label_data$hjust<-ifelse( angle < -90, 1, 0)
label_data$angle <- ifelse(angle < -90, angle+180, angle)
p <- ggplot(df1, aes(x=as.factor(No), y= Score)) +
geom_bar(stat = "identity", fill=alpha("skyblue", 0.4)) +
ylim(-1.0, 1.5) +
theme_minimal() +
theme(
axis.text = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank(),
plot.margin = unit(rep(0,8), "cm")
) +
coord_polar(start=0) +
geom_text(data = label_data, aes(x=No, y=Score+0.1, label=DrugID,
hjust=hjust, vjust=-0.02), color = "black", fontface=2,
alpha=2.0, size=2.5, angle=label_data$angle, inherit.aes = FALSE)
+
annotate("text", x=No, y=Score+0.1, label=DrugID,
hjust=hjust, vjust=-0.02, alpha=2.0, size=2.5 )