我无法使用ggiraph在这个闪亮的应用程序中右对齐 y 轴标签。
请在此处找到正在运行的应用程序、问题图片、代码和应用程序:https ://eduardo757ag.shinyapps.io/test_labels/
我尝试使用theme(axis.text.y = element_text(hjust=1))无济于事。
谢谢你的帮助!
标题:“test1”作者:“edu”日期:''输出:html_document:突出显示:探戈主题:日志运行时:闪亮
library(tidyverse)
library(ggiraph)
library(shiny)
library(survey)
data(api)
api_test <- apiclus1 %>%
dplyr::group_by(cname) %>%
dplyr::summarise_at(vars(acs.k3:acs.46), mean,na.rm=T) %>%
pivot_longer(2:3,names_to = "variable",values_to = "value") %>%
dplyr::mutate(
IOMmission =
case_when(cname=="Alameda" ~ "A very very long long label, yes",
T~cname))
api_test$tooltip <- c(paste0(api_test$cname, "\n", api_test$value))
shinyApp(
# ui.R ----
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput(inputId = "Variable",
label = "Select a survey question",
choices= unique(api_test$variable)),
width = 4,
style = "font-family: 'Georgia'"),
mainPanel(
girafeOutput("mygplot1"),
width = 8))
),
# server.R ----
server <- function(input, output) {
output$mygplot1 <- renderGirafe({
girafe(ggobj =
ggplot(
api_test, aes(x= value ,
y=reorder(cname,value),
tooltip=tooltip,
data_id=cname)) +
geom_bar_interactive(
aes(alpha=.5),
stat='identity',
fill = "#56B4E9",
data= api_test[api_test$variable == input$Variable, ]) +
labs(
y = NULL,
x = "Average",
caption = paste("Data X: ", api_test[api_test$variable == input$Variable, ]$value),
title=input$Variable) +
geom_vline(xintercept = 0, color="black", size=1) +
scale_x_continuous(
position = "top",
labels = scales::number_format(suffix = "%"),
expand = expand_scale(mult = c(0, 0.05))) +
theme(
axis.text.y = element_text(hjust=1),
plot.title.position = "plot",
panel.grid.major.y = element_blank(),
panel.grid.major.x = element_line(size = 1, colour = "grey80"),
panel.grid.minor.x = element_blank(),
legend.position = "none",
text=element_text(family="Georgia",size=12))
,
height_svg=10,
width_svg =8) %>%
girafe_options(ggiraph::opts_hover(css="fill:#22222288;cursor:pointer;"))
})},
options = list(height = 740))