Changing the name of the terms in ggally::ggcoef
Given the following example
iris_fat < iris %>% mutate(is_fat = factor(ifelse(Sepal.Width * Petal.Width > 6 ,"fat", "not_fat")))
reg < lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + is_fat, data = iris_fat)
GGally::ggcoef(reg)
How can I change the name of the term is_fatnot_fat
to something else.
1 answer

My bad on the earlier comment, didn't read it carefully.
ggcoef creates a list, just like the other ggplot functions. The first element, data, is a dataframe in which
term
maps to the yaxis. If you're curious, trystr(test_plot$data)
or examine it in RStudiotest_plot < ggcoef(reg) test_plot$data$term < c("(Intercept)", "is_fat", "Petal.Length", "Petal.Width", "Sepal.Width")
See also questions close to this topic

The application failed to start (exited with code 1) in R Shiny
I am getting the error " The application failed to start (exited with code 1)" while deploying shiny app.
The error message is attached.In console I get the following message after deploying:
Preparing to deploy application...DONE Uploading bundle for application: 365672...DONE Deploying bundle: 1444503 for application: 365672 ... Waiting for task: 533366947 building: Parsing manifest building: Building image: 1457861 building: Fetching packages building: Installing packages building: Installing files building: Pushing image: 1457861 deploying: Starting instances rollforward: Activating new instances success: Stopping old instances Application successfully deployed to https://programmingrpython.shinyapps.io/shinyapp/
The application runs locally. However I get these messages in the console when I run the app:
The following object is masked from ‘package:ggplot2’: last_plot The following object is masked from ‘package:stats’: filter The following object is masked from ‘package:graphics’: layout Warning in origRenderFunc() : Ignoring explicitly provided widget ID "52982fb160e2"; Shiny doesn't use them Warning in origRenderFunc() : Ignoring explicitly provided widget ID "5298324e516f"; Shiny doesn't use them
Packages I am using are :
library(shiny) library(plotly) library(data.table)
Is it because of the warning messages ? I have followed https://github.com/ropensci/plotly/issues/985 but still I am getting this warning.
Can any please suggest why the error message is shown after deployment?

how to convert discontinuous dates into time series for time forecasting in r?
This is the dataset which has discontinuous dates
SaleDate Netsales 1 20121201 83.60 3 20121205 26103.25 4 20121206 268037.95 5 20121207 85826.25 6 20121208 25390.25 sale_ts<ts(sales$Netsales,start=2012,end=2017,frequency = 365)
When i am using the above line of code it is taking the dates as continuous and ignoring the missing dates.

Finding the inverse multivariate normal CDF in R
Given a ddimensional input u, I am trying to find the x (also ddimensional) that satisfies the following equation in R.
u = 0.5* CDF(x,mean1,sigma1) + 0.5*CDF(x,mean2,sigma2)
. Here mean1,mean2,sigma1,sigma2 are known quantities of appropriate dimensions.If I know x, and I want to find u, I would use the
mvtnorm package
0.5* pmvnorm(c(0,0),mean=c(0,0),sigma = matrix(c(1,0,0,1),ncol=2) ) + 0.5* pmvnorm(c(0,0),mean=c(0,0),sigma = matrix(c(1,0,0,1),ncol=2) ) [1] 0.25 attr(,"error") [1] 1e15 attr(,"msg") [1] "Normal Completion"
Here x = (0,0) is the input and u = 0.25 is the output
I am trying to accomplish the reverse where u is know and x is to be found. I tried to use
multiroot
function fromrootsolve
package but I could not follow why it does not work.> junk_fun < function(x,y) ( 0.25  0.5*pmvnorm( c(x,y) ,mean = c(0,0),sigma = matrix(c(1,0,0,1),ncol=2))+ 0.5*pmvnorm( c(x,y) ,mean = c(1,0),sigma = matrix(c(1,0,0,1),ncol=2)) ) multiroot(junk_fun, start = c(0,0))
Show Traceback
Rerun with Debug Error in checkmvArgs(lower = lower, upper = upper, mean = mean, corr = corr, : argument "y" is missing, with no default
Requesting to please help me out. Thanks in advance!!

How to Color by Class in GGally ggpairs  ggplot2  R and embed the code inside a function
I have developed code with help of cnicollet see her comments below that customizes ggpairs from package GGally see below and assigns colors by Year (so that the differences between the Years become apparent):
library(ISLR) library(data.table) library(GGally) library(ggplot2) data(Auto, package = "ISLR") Auto2 < Auto[, c(1:3, 7:8)] Auto2$year = ifelse(Auto2$year < 76, 0, 1) Auto2$cylinders < factor(Auto2$cylinders) Auto2$origin < factor(Auto2$origin) Auto2$year < factor(Auto2$year) ggpairs(Auto2 , ggplot2::aes(colour=year), lower = list(continuous = wrap("points", color = "red", alpha = 0.5), combo = wrap("box", color = "orange", alpha = 0.3), discrete = wrap("facetbar", color = "yellow", alpha = 0.3) ), diag = list(continuous = wrap("densityDiag", color = "blue", alpha = 0.5) ))
Now I want to embed the call inside a function which will have as arguments the data and the name of the variable that represents the class and will return the plot as an object without displaying it.
First Try:
pairplots = function(data, class){ library(GGally) library(ggplot2) p = ggpairs(data , ggplot2::aes(colour= class), lower = list(continuous = wrap("points", color = "red", alpha = 0.5), combo = wrap("box", color = "orange", alpha = 0.3), discrete = wrap("facetbar", color = "yellow", alpha = 0.3) ), diag = list(continuous = wrap("densityDiag", color = "blue", alpha = 0.5) )) p } pairplots(data = Auto2, class = 'year')
Second Try:
pairplots = function(data, class){ library(GGally) library(ggplot2) p = ggpairs(data , ggplot2::aes(colour= data[, class]), lower = list(continuous = wrap("points", color = "red", alpha = 0.5), combo = wrap("box", color = "orange", alpha = 0.3), discrete = wrap("facetbar", color = "yellow", alpha = 0.3) ), diag = list(continuous = wrap("densityDiag", color = "blue", alpha = 0.5) )) p } pairplots(data = Auto2, class = 'year')
Both attempts result to exceptions.
Your advice will be appreciated.

How to get a single Interactive Correlation scatterplot matrix triangle with R ggpairs and plotly
I am attempting to get an interactive scatterplot matrix for ~5 variables I am interested in seeing how the observations of each correlate with each other, and to spot and identify outliers. The problem is that
plotly
is behaving unpredictably, in my opinion.#sample data sample_data < data.frame(Class = sample(x= letters[1:15],size=50,replace = TRUE), Sample_number = seq(1,50,by=1), x1= rnorm(50,mean=0, sd=.5), x2= rnorm(50,mean=0.5, sd=1.5), x3= rnorm(50,mean=5, sd=.1), x4= rnorm(50,mean=0, sd=3.5), x5= rnorm(50,mean=6, sd=.005)) #creating the standard plot p1 < ggpairs(data=sample_data, # data.frame with variables columns=3:7, # columns to plot, default to all. title=paste0("Variable Correlations"), # title of the plot aes(color = Class, text=Sample_number), progress = FALSE) + theme_bw() #creating the interactive plot ggplotly(p1)
Example 1
The matrix with both triangles looks like this I get the following warnings
Warning messages: 1: Groups with fewer than two data points have been dropped. 2: Groups with fewer than two data points have been dropped. 3: Can only have one: highlight
Example 2
However, when I change to only view one triangle of the matrix this is what it gives me, with the same warnings as above:
p2 < ggpairs(data=sample_data, # data.frame with variables columns=3:7, # columns to plot, default to all. title=paste0("Variable Correlations"), # title of the plot aes(color = Class, text=Sample_number), uppper=list(continuous="points"), lower="blank", progress = FALSE)+ theme_bw() ggplotly(p2)
Objective
But if I were to use only the standard (noninteractive)
ggpairs
output it looks pretty nice: This time I only get theWarning messages: 1: Groups with fewer than two data points have been dropped.
It would be awesome if someone had any ideas on how to make aploty
subplot just as the standardggpairs
example so to enable the interactivity. 
Parcoordplot with density behaviour
I am using GGally R package to draw a parcoordplot, but I noticed that if you have two equal rows, one with label 0 and the other with label 1, the color of the line will be the color of the last row. For instance if you have the following dataset:
[,1] [,2] [,3] [1,] 1 1 1 [2,] 1 1 1 [3,] 1 1 0
And you if call ggparcoord(dataset, columns = 1:2, groupColumn = 'V3',scale = 'globalminmax') the color that you will see is the color for label 0.
However, I do not want the last color but the most predominant one. In this case since I have three equal rows, two with label 1 and other with label 0, I want to show the color for label 1 independently of the row order. How can I do this?