r - ggvis 中的图例方向

标签 r shiny ggvis

在ggvis中如何使图例垂直?

mtcars %>% ggvis(x = ~wt, y = ~mpg, fill = ~cyl) %>%
layer_points() %>%
add_legend("fill",properties = legend_props( legend = list(x = 500, y = 50)))

它将图例水平放置。我希望它是垂直的。

最佳答案

试试下面的代码:

mtcars %>% ggvis(~wt, ~mpg, size = ~cyl, fill = ~cyl) %>% layer_points() %>% add_legend(c("size", "fill"))

输出图表:

enter image description here

希望这对您有所帮助。

编辑:

我探索了 add_legend 属性,不幸的是,目前我还没有看到使用 ggvis 实现垂直连续缩放图例的任何方法,但是可以使用 实现ggplot2

R代码:

ggplot(mtcars, aes(wt, mpg, color = cyl))+geom_point()

输出图表:

enter image description here

关于r - ggvis 中的图例方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30396854/

相关文章:

r - 帮助加速 R 中的循环

r - 使用 bash 转换数字序列

r - 通过 Shiny 编织文件的进度条

R Shiny : create non-reactive background in plotOutput

r - ggvis 中的自定义填充颜色(和其他选项)

radio-button - 基于 R Shiny 条件面板中的单选按钮的切换图

r - 如何将邻接矩阵保存为 CSV 文件?

r - 使用 dplyr 将一个 data.frame 的输出通过管道传输到另一个

r - 在 Shiny 的网络应用程序中显示错误而不是绘图

使用 ggvis 的 R markdown 返回错误 : could not find function "knit_print"