闪亮的是在ggplotly

时间:2018-02-22 21:02:18

标签: r ggplot2 shiny plotly

enter image description here

这里的中间刻面明显被压扁了,但这只发生在闪亮的地方。使用ggplotly()它看起来很好。

代码信息:d1()是一个包含4列(主题,变量,值,组)的data.frame。我希望能够仍然使用facet_wrap而不是facet_grid,因为换行允许您在轴上有不同的变量,在某些情况下,x轴(曲线上的y)将每个方面都有所不同。我尝试用固定宽度和自动宽度调整绘图输出,但没有骰子。

dput(d1)
structure(list(Topic = c("compensation", "manager", "benefits", 
"family", "communication", "worklifebalance", "perks", "compensation", 
"benefits", "manager", "communication", "worklifebalance", "family", 
"perks", "benefits", "compensation", "manager", "communication", 
"family", "worklifebalance", "perks"), variable = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L), .Label = c("Prct", "Count"), class = "factor"), 
    value = c(2.23121245555964, 0.723305136692411, 0.576192227534633, 
    0.202280250091946, 0.190020840995464, 0.153242613706019, 
    0.0122594090964816, 0.913705583756345, 0.609137055837563, 
    0.50761421319797, 0.50761421319797, 0.304568527918782, 0.203045685279188, 
    0, 1.49977276170277, 1.21193758521436, 0.893803969095592, 
    0.439327374640206, 0.348432055749129, 0.242387517042872, 
    0.0757460990758976), group = c("APAC", "APAC", "APAC", "APAC", 
    "APAC", "APAC", "APAC", "EMEA", "EMEA", "EMEA", "EMEA", "EMEA", 
    "EMEA", "EMEA", "AMERICAS", "AMERICAS", "AMERICAS", "AMERICAS", 
    "AMERICAS", "AMERICAS", "AMERICAS")), .Names = c("Topic", 
"variable", "value", "group"), class = c("data.table", "data.frame"
), row.names = c(NA, -21L), .internal.selfref = <pointer: 0x104803978>)

ui = fluidPage( mainPanel(
  'Key Words',
  fluidRow(plotlyOutput('keywords',width = auto))
))

server = function(input,output){
output$keywords = renderPlotly({
  d0 = d1
  p = ggplot(d0, aes(Topic, value)) +
    geom_point(
      aes(colour = value),
      shape = 16,
      size = 3,
      show.legend = F
    ) +
    scale_color_gradient(low = "#0091ff", high = "#f0650e") +
    coord_flip() +facet_wrap(~ group, scales = 'free')+
    ylab('Importance Level (Chi2)') + xlab('') +
    theme_minimal()
  ggplotly(p)
  )}
}

0 个答案:

没有答案