2015-02-15 44 views
9

Tôi muốn giao diện ggplot2 trong Ggvis. Có cách nào để đạt được điều này trong ggvis?R: ggvis - nền màu xám (như ggplot2)

enter image description here

Tôi có điều này từ ggvis:

enter image description here

Lưu ý:
1) Không thích nền trắng (rõ hơn về một màu xám từ ggplot2
2) Như bạn thấy, các thanh có vạch đen được vạch ra. Làm thế nào để có được đi xe của nó?

Mã của tôi:

Visitas_Por_Fuente %>% 
     ggvis(~Fuentes, ~sessions) %>% 
      layer_bars(width = 0.8, fill = ~Fuentes) 

dữ liệu của tôi:

as.data.frame(structure(list(date = structure(c(1417410000, 1417410000, 1417410000, 
1417410000, 1417410000, 1417410000, 1417496400, 1417496400, 1417496400, 
1417496400, 1417496400, 1417496400, 1417496400, 1417582800, 1417582800, 
1417582800, 1417582800, 1417582800, 1417582800, 1417582800, 1417669200, 
1417669200, 1417669200, 1417669200, 1417669200, 1417669200, 1417669200, 
1417755600, 1417755600, 1417755600, 1417755600, 1417755600, 1417755600, 
1417842000, 1417842000, 1417842000, 1417842000, 1417842000, 1417842000, 
1417842000, 1417928400, 1417928400, 1417928400, 1417928400, 1417928400, 
1417928400, 1417928400, 1418014800, 1418014800, 1418014800, 1418014800, 
1418014800, 1418014800, 1418014800, 1418101200, 1418101200, 1418101200, 
1418101200, 1418101200, 1418101200, 1418101200, 1418187600, 1418187600, 
1418187600, 1418187600, 1418187600, 1418187600, 1418187600, 1418274000, 
1418274000, 1418274000, 1418274000, 1418274000, 1418274000, 1418274000, 
1418360400, 1418360400, 1418360400, 1418360400, 1418360400, 1418360400, 
1418360400, 1418446800, 1418446800, 1418446800, 1418446800, 1418446800, 
1418446800, 1418446800, 1418533200, 1418533200, 1418533200, 1418533200, 
1418533200, 1418533200, 1418533200, 1418619600, 1418619600, 1418619600, 
1418619600, 1418619600, 1418619600, 1418619600, 1418706000, 1418706000, 
1418706000, 1418706000, 1418706000, 1418706000, 1418706000, 1418792400, 
1418792400, 1418792400, 1418792400, 1418792400, 1418792400, 1418792400, 
1418878800, 1418878800, 1418878800, 1418878800, 1418878800, 1418878800, 
1418878800, 1418965200, 1418965200, 1418965200, 1418965200, 1418965200, 
1418965200, 1418965200, 1419051600, 1419051600, 1419051600, 1419051600, 
1419051600, 1419051600, 1419051600, 1419138000, 1419138000, 1419138000, 
1419138000, 1419138000, 1419138000, 1419224400, 1419224400, 1419224400, 
1419224400, 1419224400, 1419224400, 1419224400, 1419310800, 1419310800, 
1419310800, 1419310800, 1419310800, 1419310800, 1419397200, 1419397200, 
1419397200, 1419397200, 1419397200, 1419397200, 1419397200, 1419483600, 
1419483600, 1419483600, 1419483600, 1419483600, 1419483600, 1419483600, 
1419570000, 1419570000, 1419570000, 1419570000, 1419570000, 1419570000, 
1419656400, 1419656400, 1419656400, 1419656400, 1419656400, 1419656400, 
1419742800, 1419742800, 1419742800, 1419742800, 1419742800, 1419742800, 
1419742800, 1419829200, 1419829200, 1419829200, 1419829200, 1419829200, 
1419829200, 1419915600, 1419915600, 1419915600, 1419915600, 1419915600, 
1419915600, 1419915600, 1420002000, 1420002000, 1420002000, 1420002000, 
1420002000), class = c("POSIXct", "POSIXt"), tzone = "America/Lima"), 
    Fuentes = c("Adwords", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Adwords", "Campañas", "Directo", 
    "Email", "Referencias", "SEO", "Social Media", "Adwords", 
    "Campañas", "Directo", "Email", "Referencias", "SEO", "Social Media", 
    "Adwords", "Campañas", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Campañas", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Adwords", "Campañas", "Directo", 
    "Email", "Referencias", "SEO", "Social Media", "Adwords", 
    "Campañas", "Directo", "Email", "Referencias", "SEO", "Social Media", 
    "Adwords", "Campañas", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Adwords", "Campañas", "Directo", 
    "Email", "Referencias", "SEO", "Social Media", "Adwords", 
    "Campañas", "Directo", "Email", "Referencias", "SEO", "Social Media", 
    "Adwords", "Campañas", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Adwords", "Campañas", "Directo", 
    "Email", "Referencias", "SEO", "Social Media", "Adwords", 
    "Campañas", "Directo", "Email", "Referencias", "SEO", "Social Media", 
    "Adwords", "Campañas", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Adwords", "Campañas", "Directo", 
    "Email", "Referencias", "SEO", "Social Media", "Adwords", 
    "Campañas", "Directo", "Email", "Referencias", "SEO", "Social Media", 
    "Adwords", "Campañas", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Adwords", "Campañas", "Directo", 
    "Email", "Referencias", "SEO", "Social Media", "Adwords", 
    "Campañas", "Directo", "Email", "Referencias", "SEO", "Social Media", 
    "Adwords", "Campañas", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Campañas", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Adwords", "Campañas", "Directo", 
    "Email", "Referencias", "SEO", "Social Media", "Campañas", 
    "Directo", "Email", "Referencias", "SEO", "Social Media", 
    "Adwords", "Campañas", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Adwords", "Campañas", "Directo", 
    "Email", "Referencias", "SEO", "Social Media", "Campañas", 
    "Directo", "Email", "Referencias", "SEO", "Social Media", 
    "Campañas", "Directo", "Email", "Referencias", "SEO", "Social Media", 
    "Adwords", "Campañas", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Campañas", "Directo", "Email", "Referencias", 
    "SEO", "Social Media", "Adwords", "Campañas", "Directo", 
    "Email", "Referencias", "SEO", "Social Media", "Directo", 
    "Email", "Referencias", "SEO", "Social Media"), sessions = c(10L, 
    326L, 18L, 527L, 999L, 52L, 3L, 7L, 324L, 19L, 498L, 933L, 
    44L, 5L, 12L, 363L, 15L, 546L, 1206L, 202L, 7L, 12L, 1122L, 
    27L, 1249L, 5168L, 607L, 17L, 432L, 22L, 527L, 1553L, 637L, 
    5L, 5L, 356L, 16L, 507L, 1901L, 487L, 4L, 8L, 312L, 30L, 
    500L, 1622L, 370L, 3L, 11L, 341L, 18L, 504L, 1312L, 352L, 
    2L, 13L, 1188L, 33L, 682L, 2008L, 1508L, 3L, 15L, 1086L, 
    36L, 646L, 2124L, 380L, 3L, 11L, 355L, 17L, 383L, 1054L, 
    236L, 2L, 9L, 321L, 15L, 370L, 1118L, 245L, 7L, 9L, 259L, 
    13L, 332L, 1261L, 230L, 3L, 7L, 539L, 9L, 626L, 2336L, 256L, 
    1L, 12L, 292L, 8L, 386L, 1070L, 220L, 1L, 12L, 278L, 9L, 
    393L, 1129L, 22L, 1L, 16L, 521L, 18L, 665L, 2400L, 20L, 1L, 
    13L, 204L, 7L, 258L, 789L, 11L, 2L, 12L, 253L, 6L, 277L, 
    803L, 9L, 1L, 4L, 262L, 8L, 324L, 960L, 9L, 3L, 442L, 15L, 
    516L, 1890L, 16L, 2L, 14L, 249L, 8L, 240L, 688L, 11L, 15L, 
    182L, 7L, 200L, 548L, 5L, 2L, 3L, 171L, 7L, 183L, 480L, 5L, 
    1L, 3L, 176L, 5L, 231L, 506L, 6L, 15L, 283L, 18L, 322L, 786L, 
    11L, 13L, 210L, 9L, 232L, 649L, 2L, 1L, 2L, 258L, 4L, 306L, 
    891L, 9L, 4L, 183L, 10L, 293L, 634L, 4L, 1L, 3L, 188L, 9L, 
    244L, 566L, 11L, 134L, 1L, 176L, 453L, 4L)), .Names = c("date", 
"Fuentes", "sessions"), row.names = c(NA, -208L), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"), vars = list(date), drop = TRUE)) 
+0

Vì lý do nào đó, ggvis không nhận ra "ñ" từ "Campañas". Làm thế nào để làm cho nó xuất hiện? –

+0

không chắc chắn bạn cần phải đặt các yếu tố() trong mã này - nó đã được phân loại – jalapic

+0

@ jalapic, nó là tốt hơn không sử dụng yếu tố(). Nó đã cho tôi vấn đề trong sáng bóng. Trong Shiny, nó đã biểu quyết nó ngay lần đầu tiên, nhưng sau khi thay đổi datarangeInput, cốt truyện bị biến mất. Điều này không xảy ra nếu bạn cất cánh phần ~ factor(). Tôi đã thay đổi mã của mình để phản ánh điều này. –

Trả lời

10

Nếu đầu ra của bạn là một ứng dụng Shiny Shiny hoặc tài liệu, bạn có thể thay đổi màu nền với một số css. Lưu ý rằng điều này sẽ chỉ hoạt động chính xác khi ggvis được hiển thị dưới dạng svg (không phải canvas). Cũng lưu ý rằng nó sẽ không hiển thị chính xác trong trình xem Rstudio. Thêm một nơi nào đó trong tài liệu trước khi ggvis được tạo ra:

<style type="text/css"> 
rect.background { 
    fill: #E6E6E6 !important; 
} 
</style> 

Sau đó, để có được đường lưới màu trắng và để loại bỏ các biên giới vạch, mã của bạn sẽ trông như thế

Visitas_Por_Fuente %>% 
     ggvis(~Fuentes, ~sessions) %>% 
      layer_bars(width = 0.8, fill = ~Fuentes, strokeWidth := 0) %>% 
      add_axis("x", properties = axis_props(grid = list(stroke = "white"))) %>% 
      add_axis("y", properties = axis_props(grid = list(stroke = "white"))) 

Chỉnh sửa này: Đây là một tối thiểu. Rmd tài liệu cho thấy phải làm gì. Mở phần này trong Rstudio và nhấp vào "Chạy tài liệu" để xem kết quả.

--- 
title: "Untitled" 
output: html_document 
runtime: shiny 
--- 

<style type="text/css"> 
rect.background { 
    fill: #E6E6E6 !important; 
} 
</style> 

```{r, echo=FALSE} 
library(ggvis) 
mtcars %>% 
    ggvis(~cyl, ~mpg) %>% 
    layer_bars(width = 0.8, fill:= "slateblue", strokeWidth := 0) %>% 
    add_axis("x", properties = axis_props(grid = list(stroke = "white"))) %>% 
    add_axis("y", properties = axis_props(grid = list(stroke = "white"))) 
``` 
Các vấn đề liên quan