简体   繁体   English

散景图图例-放置不佳

[英]r bokeh chart legend - placed poorly move

散景图带有难看的图例位置 I have been working in flexdashboards using rbokeh to draw some dynamic graphs. 我一直在使用rbokeh在flexdashboard中绘制一些动态图。 Because this is a bar chart mapped to categorical data in the variable Classification , I am unable to manually create a legend, which is fine because rbokeh does it automatically. 因为这是映射到变量分类数据的条形图Classification ,我无法手动创建一个图例,因为rbokeh自动执行它是细。

However, I am having some issues with the legend and labeling: 但是,图例和标签存在一些问题:

  1. It is placed horribly, I would like to tell r to place in the upper left hand corner to get it away from bars with content. 它被可怕地放置,我想告诉r放置在左上角,以使其远离带有内容的条。

  2. I would like to drop the red ab_line into the legend and label it (using standard legend = will not work because of the mapped variables in the base chart 我想将红色的ab_line放到图例中并标记它(使用标准的legend =由于基本图中的映射变量而无法使用

  3. This graph needs to be 508 compliant for translation, the flexdashboard is, as well as the bokeh tools on the left hand margin and the keys in the pop ups, but the values and labels remain in English. 该图需要兼容508,flexdashboard以及左边缘的bokeh工具和弹出窗口中的键,但值和标签仍为英文。 Does anyone have a way of making the charts responsive to google translate? 有谁有办法使图表响应Google翻译? I am fine if that involves editing the extruded page....I will just need more guidance in doing it there. 如果那涉及编辑拉伸页面,那很好。...在那儿,我只需要更多指导即可。

    figure(title=" Confirmed & Probable Cases by Year",width= 1400, height =350)%>% ly_bar(x=Year, y= count, position='stack', data=probConf, width=.9,hover=TRUE, legend=TRUE, color=Classification) %>% x_axis(label ='Year')%>% y_axis(label ='Cases')%>% ly_abline(v=17.5, legend=NULL, color = "red", width =1, alpha=.5)%>% [![enter image description here][1]][1]set_palette(discrete_color = pal_color(c("#ee9f00", "#ffcc66")))

To answer number 1, you can use legend_location to specify the placement of the legend (see example below and note I replaced the probConf data with the lattice barley dataset so that it is reproducible for others). 要回答第一个数字,您可以使用legend_location指定图例的位置(请参见下面的示例,并注意我用格子大麦数据集替换了probConf数据,以便其他数据可重复使用)。

figure(title = " Confirmed & Probable Cases by Year", width = 1400,
  height = 350, legend_location = "top_left") %>%
  ly_bar(x = variety, y = yield, position = "stack", data = lattice::barley,
    width = 0.9, hover = TRUE, legend = TRUE, color = year) %>%
  x_axis(label = "Year") %>%
  y_axis(label = "Cases") %>%
  ly_abline(v = "Svansota:1", color = "red",  width = 1, alpha = 0.5) %>%
  set_palette(discrete_color = pal_color(c("#ee9f00", "#ffcc66")))

#2 is currently difficult to achieve in rbokeh but it should be more robust to situations like this (mixing mapped and user-defined legend entries) in the future. #2当前在rbokeh中很难实现,但将来它应该对这种情况(混合映射的和用户定义的图例条目)更加健壮。 If ly_abline() were to accept data as an argument, you could use use a mapped variable for color to resolve the issue. 如果ly_abline()接受数据作为参数,则可以使用映射的变量作为颜色来解决问题。

One solution that isn't very pretty is to manually draw the bar chart polygons with ly_rect (one call to ly_rect for each classification) and use custom legend entries for those and then add a custom legend entry for ly_abline . 一种不太理想的解决方案是使用ly_rect手动绘制条形图多边形(每个分类都调用ly_rect ),并为它们使用自定义图例条目,然后为ly_abline添加自定义图例条目。

I do not know the answer to #3. 我不知道第三种答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM