logo
down
shadow

Make dual X-axs based on different variables using ggvis


Make dual X-axs based on different variables using ggvis

Content Index :

Make dual X-axs based on different variables using ggvis
Tag : r , By : 小和尚
Date : December 01 2020, 05:00 PM

I hope this helps . The second axis needs to have a 'name' in order for the axis to know which variable to reflect. See below:
df <- data.frame(X1 = rep(1:5,1), 
                 X2 = rep(4:8,1), 
                 var1 = sample(1:10,5), 
                 row.names = c(1:5))

library("ggvis")
df %>%
  ggvis(~X1) %>%
  #this is the line plotted
  layer_lines(y = ~ var1) %>%
  #and this is the bottom axis as plotted normally
  add_axis("x", orient = "bottom", title = "X1")  %>%
  #now we add a second axis and we name it 'x2'. The name is given
  #at the scale argument 
  add_axis("x", scale = 'x2',  orient = "top", title = "X2" ) %>%
  #and now we plot the second x-axis using the name created above
  #i.e. scale='x2'
  layer_lines(prop('x' , ~X2,  scale='x2'))

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Problems using ggvis in rMarkdown with variables


Tag : development , By : richardD
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


Tag : r , By : Ernie
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


Tag : r , By : nhuser
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


Tag : r , By : Navin
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() 
Related Posts Related QUESTIONS :
  • Set the y limits of an added average line of a plotly plot
  • how to calculate a new column after grouping with dplyr
  • Extract data from rows creating new columns using R
  • Create a filled area line plot with plotly
  • When do I need parentheses around an if statement to control the sequence of a formula in R?
  • my graph in ggplot2 contains an "e" character in y-axis
  • Making variables immutable in R
  • R: Difference between the subsequent ranks of a item group by date
  • Match data within multiple time-frames with dplyr
  • Conditional manipulation and extension of rows in data.table also considering previous extensions without for-loop
  • Conditional formula referring to preview row in DF not working
  • Set hoverinfo text in plotly scatterplot
  • Histogram of Sums from Categorical/Binary Data
  • Efficiently find set differences and generate random sample
  • Find closest points from data set B to point in data set A, using lat long in R
  • dplyr join on column A OR column B
  • Replace all string if row starts with (within a column)
  • Is there a possibility to combine position_stack and nudge_x in a stacked bar chart in ggplot2?
  • How can I extract bounding boxes in a row-wise manner using R?
  • How do I easily sum up values in different columns?
  • Reading numeric Date value from CSV file to data.frame in "R"
  • R programming: creating a stacked bar graph, with variable colors for each stacked bar
  • How to identify all columns that contain binary representation
  • Filter different groups by different factor levels
  • Saving .xlsx file to disc, form http post request
  • Add an "all" option under the filter that selects the number of rows displayed in a datatable
  • How to select second column of every xts in list
  • Generate a frequency dataframe out of an input dataframe
  • Why manual autocorrelation does not match acf() results?
  • Merge 3 dataframes which are different to each other
  • remove adjacent duplicates from string
  • How to change the position of stacked stacked bar chart in ggplot in R?
  • How to divide each of a range a variables by a second range of variables in R
  • Why do I need to assemble vector before scaling in Spark?
  • How to select individuals which appear in multiple groups?
  • How can I fill columns based on values in another column?
  • 32 bit R and 64 bit R: output differs
  • Remove a single backslash in paste0 output
  • ggplot2 different label for the first break
  • TSP in R, with given distances
  • How to find the given value from the range of values?
  • Solution on R group by issue _ multiple combination
  • Transform multiple columns with a function that uses different arguments per column
  • How can I parse a string with the format "1/16/2019 1:24:51" into a POSIXct or other date variable?
  • How to plot a box plot in R for outlier detection for a huge number of rows?
  • How to change column name according to another dataframe in R?
  • `sjPlot::tab_df()`--how to set the number of decimal places?
  • time average for specific time range in r
  • joining dataframes by closest time and another key in r
  • How to create nested for loop for a certain range
  • New category based on sequence of date ranges
  • how to extract formula from coxph model summary in R?
  • add row based on variable condition in R
  • Generating the sequence 111122222333334
  • Unable to use has_goog_key() in R
  • how to multiply each row with a scaler in corresponding column?
  • R is not recognizing levels of a factor as the same. Is there a way to do this?
  • Calculating mean of replicate experiment result values in a column based on multiple columns using R
  • Best method to extract the first instance of a string between specified keywords using data.table
  • ignore optional combination of alphanumeric characters in str_extract
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com