r

ggplot legend: change order of the automatic legend

独自空忆成欢 提交于 2021-02-10 08:40:08
问题 I am struggling with the legend order in ggplot when there are several group of plots. Here is an example: library(ggplot2) library(data.table) data <- data.table(time = rep(1:50,4),dampingtime = rep(c(4,8,12,16),each = 50), excitation = rep(c(rep(0,10),rep(1,10),rep(0,30)),4)) data[,signal := time + .GRP, by = dampingtime] data[,dampingtime := as.factor(dampingtime)] Here I have > levels(data$dampingtime) [1] "4" "8" "12" "16" which I did accordingly to ggplot legends - change labels, order

Error exposing c++ class method with reference parameter using Rcpp modules

六眼飞鱼酱① 提交于 2021-02-10 08:36:41
问题 My goal is to build a dataset class and a model class, and expose both of them to R. The model class has a train() method that takes a reference to a dataset instance, and this seems to be at the root of my issue. Here's what this looks like //glue.cpp #include <Rcpp.h> class MyData { public: MyData() = default; }; class MyModel { public: MyModel() = default; void train(const MyData& data) { Rcpp::Rcout << "training model... "; }; }; // Expose MyData RCPP_MODULE(MyData){ Rcpp::class_<MyData>(

ggraph network plot: specify node coordinates

北战南征 提交于 2021-02-10 08:14:54
问题 Trying to plot a network with the ggraph package and specify the coordinates of each node. While I can implement this with the igraph package - I cannot do this with the ggraph package. # reproducible example to generate a random graph library(igraph) g1 <- erdos.renyi.game(20, 1/2) plot(g1) # function to produce coordinates for each node in order of the node # degree (number of links per node) coord <- function(g){ n.nod <- length(V(g)) mat.c <- matrix(0, nrow = n.nod, ncol = 2) deg <-

ggraph network plot: specify node coordinates

走远了吗. 提交于 2021-02-10 08:14:54
问题 Trying to plot a network with the ggraph package and specify the coordinates of each node. While I can implement this with the igraph package - I cannot do this with the ggraph package. # reproducible example to generate a random graph library(igraph) g1 <- erdos.renyi.game(20, 1/2) plot(g1) # function to produce coordinates for each node in order of the node # degree (number of links per node) coord <- function(g){ n.nod <- length(V(g)) mat.c <- matrix(0, nrow = n.nod, ncol = 2) deg <-

Plotly: How to customize colors in a donut chart?

折月煮酒 提交于 2021-02-10 08:13:19
问题 I would like to ask you if you could help me in customizing of colors in a donut chart created by plotly. The problem is following - I have to recreate a dashboard (from an excel file to a html file). A part of the dashboard is a chart providing us with information about early production of each entity. The chart is a donut chart type by plotly. As each entity is defined by a specific color (defined in RGB) throughout whole dashboard, I need to keep these colors in the donut chart as well.

ggraph network plot: specify node coordinates

梦想的初衷 提交于 2021-02-10 08:13:04
问题 Trying to plot a network with the ggraph package and specify the coordinates of each node. While I can implement this with the igraph package - I cannot do this with the ggraph package. # reproducible example to generate a random graph library(igraph) g1 <- erdos.renyi.game(20, 1/2) plot(g1) # function to produce coordinates for each node in order of the node # degree (number of links per node) coord <- function(g){ n.nod <- length(V(g)) mat.c <- matrix(0, nrow = n.nod, ncol = 2) deg <-

ggraph network plot: specify node coordinates

南楼画角 提交于 2021-02-10 08:12:31
问题 Trying to plot a network with the ggraph package and specify the coordinates of each node. While I can implement this with the igraph package - I cannot do this with the ggraph package. # reproducible example to generate a random graph library(igraph) g1 <- erdos.renyi.game(20, 1/2) plot(g1) # function to produce coordinates for each node in order of the node # degree (number of links per node) coord <- function(g){ n.nod <- length(V(g)) mat.c <- matrix(0, nrow = n.nod, ncol = 2) deg <-

ggraph network plot: specify node coordinates

人走茶凉 提交于 2021-02-10 08:11:44
问题 Trying to plot a network with the ggraph package and specify the coordinates of each node. While I can implement this with the igraph package - I cannot do this with the ggraph package. # reproducible example to generate a random graph library(igraph) g1 <- erdos.renyi.game(20, 1/2) plot(g1) # function to produce coordinates for each node in order of the node # degree (number of links per node) coord <- function(g){ n.nod <- length(V(g)) mat.c <- matrix(0, nrow = n.nod, ncol = 2) deg <-

ggraph network plot: specify node coordinates

旧街凉风 提交于 2021-02-10 08:11:16
问题 Trying to plot a network with the ggraph package and specify the coordinates of each node. While I can implement this with the igraph package - I cannot do this with the ggraph package. # reproducible example to generate a random graph library(igraph) g1 <- erdos.renyi.game(20, 1/2) plot(g1) # function to produce coordinates for each node in order of the node # degree (number of links per node) coord <- function(g){ n.nod <- length(V(g)) mat.c <- matrix(0, nrow = n.nod, ncol = 2) deg <-

Plotting Custom PDF in R

拥有回忆 提交于 2021-02-10 08:10:48
问题 Given: Consider the density function $\phi$ defined on $\mathbb{R}$ for $a\in \mathbb{R}$ and $b \in \mathbb{R}_+^\star$ such that $\forall x \in \mathbb{R}$ , $$ \phi(x; a,b) = \frac{1}{\sqrt{2\pi b^2}}e^{-\frac{1}{2}\left(\frac{x-a}{b}\right)^2}. $$ Consider now the so-called Bart Simpson probability density function $f$ given by \begin{eqnarray} \label{eq:bart:1d:1} f(x) = \frac{1}{2}\phi(x; 0,1) + \frac{1}{10}\sum_{j=0}^4{\phi(x; (j/2)-1, 1/10)}. \end{eqnarray} Questions: Plot the pdf $f$