Problems using ggvis in rMarkdown with variables
Date : March 29 2020, 07:55 AM
around this issue Hi having a couple of problems , This should do it: ---
title: "Untitled"
output: html_document
runtime: shiny
---
```{r, echo = FALSE, message=FALSE}
library(ggplot2)
library(ggvis)
library(dplyr)
selectInput("category3", "Choose Dataset:", c("mpg", "disp", "qsec"))
# ggplot renders correctly within renderPlot
renderPlot({
print(input$category3)
ggplot(mtcars,aes_string(input$category3,"disp"))+geom_point()
})
# ggvis with dynamically changing columns
reactive({
if (!is.null(input$category3))
col <- input$category3
else
col <- "mpg"
mtcars %>% ggvis(prop("x", as.name(col)), ~disp)
}) %>% bind_shiny('foo')
ggvisOutput('foo')
```
|
How to align a bar and a line chart in ggvis in a dual y-axes plot?
Tag : r , By : user150744
Date : March 29 2020, 07:55 AM
I hope this helps . After about 4 months and a bit of researching I found a way around this issue although it is kind of a hack: mydf2 %>% as.data.frame() %>% mutate(Species2= as.numeric(Species)) %>%
ggvis(x = ~ Species2, y = ~ Sepal.Length ) %>%
layer_bars(fillOpacity := 0.1, width = 0.9 ) %>%
add_axis("y", "ywidth", orient = "right", grid = FALSE) %>%
layer_lines(prop("y", ~ Sepal.Width, scale = "ywidth")) %>%
add_axis('x', title='the species', properties = axis_props(labels=list(fill='blank'))) %>%
add_axis('x', 'myx2', orient='bottom', title='', grid=F) %>%
layer_lines(prop("x", ~ Species, scale = "myx2"), stroke := 'blank')
|
plot 2 variables on Y axis, using ggvis in R
Date : March 29 2020, 07:55 AM
this one helps. I have a dataset that looks like this , You can do it this way: library(ggvis)
DT %>% ggvis(x= ~YEAR) %>%
layer_lines(y= ~A, stroke:='blue') %>%
layer_lines(y= ~B, stroke:='orange')
library(reshape2)
DT2 <- melt(DT, 'YEAR', c('A','B'))
DT2 %>% ggvis(~YEAR, ~value, stroke=~variable) %>% layer_lines()
|
ggvis add_tooltip character variables don't render
Date : March 29 2020, 07:55 AM
I wish this helpful for you On layer_paths you group the data frame by group and you use a fill of the total and you also choose long and lat in your original ggvis call. Therefore, your data frame going in add_tooltip contains exactly those columns i.e. there is no name column. A fast check showed me that there each group corresponds to only one name as you can see below: > table(jor$group, jor$name)
ajlun amman aqaba balqa irbid jarash karak ma`an madaba mafraq tafilah zarqa
2009.1 0 0 87 0 0 0 0 0 0 0 0 0
2010.1 0 0 0 0 0 0 0 0 0 115 0 0
2011.1 0 102 0 0 0 0 0 0 0 0 0 0
2012.1 0 0 0 0 0 0 0 0 0 0 67 0
2013.1 0 0 0 0 0 0 0 70 0 0 0 0
2014.1 0 0 0 0 159 0 0 0 0 0 0 0
2015.1 41 0 0 0 0 0 0 0 0 0 0 0
2016.1 0 0 0 0 0 42 0 0 0 0 0 0
2017.1 0 0 0 80 0 0 0 0 0 0 0 0
2018.1 0 0 0 0 0 0 0 0 60 0 0 0
2019.1 0 0 0 0 0 0 74 0 0 0 0 0
2020.1 0 0 0 0 0 0 0 0 0 0 0 86
#I have added a fake total column
jor$total <- runif(983) * 100
jor %>% ggvis(~long, ~lat) %>%
layer_paths(data = jor %>% group_by(name),
strokeWidth := 0, fill = ~total) %>%
hide_axis("x") %>% hide_axis("y") %>%
add_tooltip(function(data){paste("Gov: ", data$name, "<br>", "Total: ", as.character(data$lat))}, "hover")
jor %>% ggvis(~long, ~lat) %>%
layer_paths(data = jor %>% group_by(name),
strokeWidth := 0, fill = ~lat) %>%
hide_axis("x") %>% hide_axis("y") %>%
add_tooltip(function(data){paste("Gov: ", data$name, "<br>", "Total: ", as.character(data$lat))}, "hover")
|
Scatterplot based on 2 categorical variables using ggvis package in R
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further , I think you need factor(V3):factor(V4) instead of factor(V3*V4): salab %>%
ggvis(~V2, ~V1, fill = ~ factor(V3):factor(V4)) %>%
layer_points()
|