10
在ggplot2中,元素的大小是分開指定的。當圖形大小改變時,元素(例如圖例)不會改變。當輸出ggplot2數字的大小隨瀏覽器窗口變化時,這可能是Shiny中的一個問題。下面是一個虛擬Shiny應用程序的代碼和兩個不同瀏覽器窗口大小的輸出數字。由於其傳奇的一部分已被切斷,因此較小的數字很難看。ggplot2和Shiny:如何縮放圖形大小的圖例大小?
有沒有一種方法可以直接在ggplot2中使用圖形大小縮放圖例大小,而無需將圖形預先保存爲Shiny應用程序的圖像文件?
library(shiny)
library(ggplot2)
ui <- fluidPage(
br(), br(), br(),
plotOutput("test", height = "auto")
)
server <- function(input, output, session) {
output$test <- renderPlot(
height = function() {
0.8 * session$clientData$output_test_width
},
expr = {
aaa <- ggplot(mtcars, aes(wt, mpg, color = cyl)) +
geom_point() +
theme(legend.position = c(0.9, 0.9))
print(aaa)
}
)
}
shinyApp(ui, server)
但在小的瀏覽器窗口,傳說的頂部沒有顯示出來:
感謝。這使得數字更好。 –