I am currently using nPlot from rCharts package and how do I add $ signs to the y Axis?
I am thinking I need something like n1$yAxis(labels = ...) but I don't think nPlot supports this?
test <- data.frame(object = c("A", "B"), price = c(111333, 876176))
test$Test <- "TEST"
n1 <- nPlot(price~Test, group = "object", data = test, type = "multiBarChart")
Also, it looks like nPlot is rounding to 5 significant figures (initially thought it was rounding to the nearest 10), is there a way of displaying the full value?
Thanks,
I am posting my comment as a full solution so that it is easier for others looking for it.
require(rCharts) # install the latest from the dev branch
test <- data.frame(object = c("A", "B"), price = c(111333, 876176))
test$Test <- "TEST"
n1 <- nPlot(price~Test, group = "object", data = test, type = "multiBarChart")
n1$yAxis(tickFormat = "#! function(d) {return '$' + d} !#")
Related
I am using par() function to partition the window, to accommodate three plots, but always one plot is missing. Not able to figure out why is it happening. Below is my R script function:
answer_3<-function(){
set.seed(1)
a <- runif(100)
set.seed(1)
b <- runif(100)
A<- as.data.frame(A)
B <- as.data.frame(b)
AB<-cbind(A,B)
AB_pear<-cor(x = AB,y=NULL,method = "pearson")
AB_spear<-cor(x = AB,y=NULL,method = "spearman")
AB_kend<-cor(x = AB,y=NULL,method = "kendall")
par(mfcol=c(3,1), mar=c(1,1,1,1))
#sp <-plot(AB[,1],AB[,2],main = "Plot of random uniform distribution",xlab = "uniformly distributed points_a",ylab = "uniformly distributed points_b")
library(corrplot)
Pear_p<-corrplot(corr = AB_pear,method = "circle",title = "Pearson correlogram")
Spear_p<-corrplot(corr = AB_spear,method = "circle",title = "Spearman correlogram")
Kend_p<-corrplot(corr = AB_kendall,method = "circle",title = "Kendall correlogram")
c(Pear_p,Spear_p,Kend_p)
}
The Kend_p is always missing from the plot window. What am I doing wrong?
I would like to include a 3D dynamic (i.e. one can change its perspective just by moving the plot) histogram widget in a R Shiny application.
Unfortunately I didn't find any until now.
So far the results of my searches: with threejs (e.g. here on CRAN and there on GitHub) one can use many different representations (scatterplots, surfaces, etc.) but no 3D histogram. plot3D and plot3Drgl don't have any R Shiny counterpart.
Unless something already exists my intention is to create an HTMLWidget from one of the sub-libraries of vis.js, namely graph3d.
What are your views on this issue?
Best regards,
Olivier
It's possible with plot3Drgl. Here is an example.
library(plot3Drgl)
library(shiny)
options(rgl.useNULL = TRUE)
ui <- fluidPage(
rglwidgetOutput("myWebGL")
)
server <- function(input, output) {
save <- options(rgl.inShiny = TRUE)
on.exit(options(save))
output$myWebGL <- renderRglwidget({
try(rgl.close())
V <- volcano[seq(1, nrow(volcano), by = 5),
seq(1, ncol(volcano), by = 5)] # lower resolution
hist3Drgl(z = V, col = "grey", border = "black", lighting = TRUE)
rglwidget()
})
}
shinyApp(ui, server)
My package graph3d is on CRAN now.
library(graph3d)
dat <- data.frame(x = c(1,1,2,2), y = c(1,2,1,2), z = c(1,2,3,4))
graph3d(dat, type = "bar", zMin = 0, tooltip = TRUE)
You can customize the tooltips:
graph3d(dat, type = "bar", zMin = 0,
tooltip = JS(c("function(xyz){",
" var x = 'X: ' + xyz.x.toFixed(2);",
" var y = 'Y: ' + xyz.y.toFixed(2);",
" var z = 'Z: ' + xyz.z.toFixed(2);",
" return x + '<br/>' + y + '<br/>' + z;",
"}"))
)
I realize I have to add an option to control the size of the axes labels...
Many thanks, DSGym. I didn't know this library.
In my initial message (now amended) I actually forgot to mention the dynamic feature, i.e. the ability to change the perspective of the plot just by moving it with the mouse, like with vis.js-graph3d.
It seems plots from highcharter cannot do that, or am I mistaken?
[EDIT]: I just checked with Shiny: it is static.
I am using igraph in R for network analysis. I want to display an edge attribute on each line in the plot. An example is below
df <- data.frame(a = c(0,1,2,3,4),b = c(3,4,5,6,7))
nod <- data.frame(node = c(0:7),wt = c(1:8))
pg <- graph_from_data_frame(d = df, vertices = nod,directed = F)
plot(pg)
I want the value of the "wt" feature to show up between each node on the line, or preferably, in a little gap where the line breaks.
Is it possible to make this happen?
Use the parameter edge.label to assign labels of the edges, I used - probably wrong - nod$wt. Of course, you could assign other labels.
You could use the following code:
# load the package
library(igraph)
# your code
df <- data.frame(a = c(0,1,2,3,4),b = c(3,4,5,6,7))
nod <- data.frame(node = c(0:7),wt = c(1:8))
pg <- graph_from_data_frame(d = df, vertices = nod,directed = F)
# plot function with edge.label added
plot(pg, edge.label = nod$wt)
Please, let me know whether this is what you want.
I am experimenting with R highcharter package to create a bar chart function. the code is as below. I request help in
1-How to change the format of the dataLabels to percentage ?
2-How to set X-axis label display angle. I want to set it to 45 degrees
hcbar_categorycount_vertical <- function(data=x,var=y){
df <- data.frame(prop.table(table(data[var])))
names(df) <- c(var,'Proportion')
df$Proportion <- round(df$Proportion*100,2)
df <- df%>% arrange(-Proportion)
df[,1] <- as.character(df[,1])
df[,1] <- factor(df[,1], levels = df[,1])
df$Cumulative <- round(cumsum(df$Proportion),2)
highchart(debug = TRUE) %>%
hc_xAxis(categories=df[[1]]) %>%
hc_yAxis(labels = list(format = "{value}%"), max = 100) %>%
hc_add_series(name=var,data=df$Proportion,type = "column",dataLabels = list(enabled = TRUE, format='{point.label}%'))
}
I am not sure what should be the syntax of "format" within dataLabel property list.The above code does not seem to work. I already referred to the highcharter vignette and this site : http://jkunst.com/highcharter/highcharts-api.html#hc_xaxis-and-hc_yaxis
But could not find an answer. Thanks for the help in advance.
#jeganathan-velu,
1) Try changing the '{point.label}%'by '{point.y}%'
2) See the highcharts example. You need to add to the hc_xAxis the argument labels = list(rotation = 90)
highcharter package is just the wrapper of highcharts so you can check all the examples and the well documented API from highcharts. Replicating highcharts demos
Found the answer after trial and error and some further research in http://api.highcharts.com/highcharts#xAxis.labels.rotation
Posting the updated code component for the benefit of others.
hc_xAxis(categories=df[[1]],labels = list(rotation=-45)) %>%
hc_yAxis(labels = list(format = "{value}%"), max = 100) %>%
hc_add_series(name=var,data=df$Proportion,type = "column",dataLabels = list(enabled = TRUE, format='{point.y}%'))
I am using this R package called "phyloseq" to analyze the bioinformatic data.
otumat = matrix(sample(1:100, 100, replace = TRUE), nrow = 10, ncol = 10)
otumat
rownames(otumat) <- paste0("OTU", 1:nrow(otumat))
colnames(otumat) <- paste0("Sample", 1:ncol(otumat))
otumat
taxmat = matrix(sample(letters, 70, replace = TRUE), nrow = nrow(otumat), ncol = 7)
rownames(taxmat) <- rownames(otumat)
colnames(taxmat) <- c("Domain", "Phylum", "Class", "Order", "Family", "Genus",
"Species")
taxmat
library("phyloseq")
OTU = otu_table(otumat, taxa_are_rows = TRUE)
TAX = tax_table(taxmat)
OTU
TAX
physeq = phyloseq(OTU, TAX)
physeq
plot_bar(physeq, fill = "Family")
So the bar graph generated do not stack the same Family together. For example, there are two separate "I" blocks in sample 10. I know phyloseq plot graph using ggplot2. Does any one know what ggplot2 associated codes I can add to the lot_bar(physeq, fill = "Family") to stack the same family together in the bar graph?
You need to reorder the levels of the factor being used for the x-axis. physeq presumably has a column called "Sample" (don't have the relevant package installed), you need to reorder the levels in this.
It should be possible to use a command like this
physeq$Sample <- factor(physeq$Sample, levels = paste0("Sample", 1:10))
Then it should plot correctly.
You might need to dig to find the relevant part to change
Actually, with respect, the plot_bar function does already do what you're asking:
# preliminaries
rm(list = ls())
library("phyloseq"); packageVersion("phyloseq")
data("GlobalPatterns")
gp.ch = subset_taxa(GlobalPatterns, Phylum == "Chlamydiae")
# the function call that does what you're asking for
plot_bar(gp.ch, fill = "Family")
See the following help tutorial for more details, examples:
https://joey711.github.io/phyloseq/plot_bar-examples.html
You can also specify the x-axis grouping as well.