我有以下数据和图表:
library(rcdimple)
df<- data.frame(values=rnorm(5, mean = 5,sd = 2),
labels=c("Short Label", "Medium Laaabel", "Looonnnnnggg Laaaaabbbeeeell",
"The quick brown fox jumped over the lazy dog",
"noSpacesLongLabelThatCanHopefullyBeSplitToo"))
dimple(
labels ~ values,
groups = "labels",
data = df,
type = "bar"
) %>%
xAxis(type = "addMeasureAxis", title="Just An Axis Label") %>%
#good test of orderRule on y instead of x
yAxis(type = "addCategoryAxis", orderRule = "values", title="Wrap These Labels") %>%
add_legend(
x = 0,
y = 10,
width = "100%",
height = 30,
horizontalAlign = "right"
) %>%
rcdimple::set_bounds("40.5%", "8.5%", "90%", "85%") %>%
rcdimple::add_title(html=paste0("<h4>How Could I wrap long labels?</h4>" ))
为了适合标签,我不得不将很大一部分绘图区域(40.5%)分配给标签,而不是条形图。我希望能够包装标签并为条形图中的条形提供更多空间。
我想知道是否可以这样做,是否有人可以解决?到目前为止,我已经尝试了,但没有成功:
# 1. Putting in a "<br>" where desired after a space
df$labels<-stringr::str_replace_all(stringr::str_wrap(df$labels, width = 25), "\\n", " <br> ")
# Wrapping it all in HTML, even putting that inside eval(parse(text=df$labels))....
df$labels<- shQuote(paste0('htmltools::HTML("',stringr::str_replace_all(stringr::str_wrap(df$labels, width = 25), "\\n", " <br> "),'")'), type = "cmd")
任何帮助将不胜感激。先感谢您。 -NF