RGTK2 Implementing a Scrolled Window - r

I'm writing a GUI in R that compares a bunch of different plots. I am trying to implement a scrolling window to contain the plots.
What I am having trouble with is controlling the size of a scrolledwindow using Rgtk2:
window = gtkWindow(show = FALSE)
hbox = gtkHBoxNew(homogeneous = FALSE, spacing = 0)
window$add(hbox)
vboxLoad = gtkVBoxNew(homogeneous = FALSE, spacing = 0)
hbox$add(vboxLoad)
scroll = gtkScrolledWindow()
vbox2 = gtkVBoxNew(homogeneous = FALSE, spacing = 0)
scroll$addWithViewport(vbox2)
vboxLoad$add(scroll)
framePlot = gtkFrameNew("Plot1")
framePlot2 = gtkFrameNew("Plot2")
vbox2$add(framePlot)
vbox2$add(framePlot2)
plot1 = gtkDrawingArea()
gtkWidgetSetSizeRequest(plot1,450,400)
asCairoDevice(plot1)
gtkWidgetShow(plot1)
framePlot$add(plot1)
plot2 = gtkDrawingArea()
gtkWidgetSetSizeRequest(plot2,450,400)
asCairoDevice(plot2)
gtkWidgetShow(plot2)
framePlot2$add(plot2)
Gives me something tantalizingly close to what I need, but Rgtk2 does not have a gtk_scrolled_window_set_min_content_width option and I don't know how to use adjustments to achieve the desired effect, i.e:
hadjustment = gtkAdjustmentNew(value = NULL, lower = NULL, upper = NULL, step.incr = NULL, page.incr = NULL, page.size = 600)
gtkScrolledWindowSetHadjustment(scroll, hadjustment)
does not work as a blunt instrument.
Any help would be appreciated.

As usual, I tried to attack the wrong part of the problem. Controlling the size of the box that contains the scrolled window seems to work just fine:
window = gtkWindow(show = FALSE)
hbox = gtkHBoxNew(homogeneous = FALSE, spacing = 0)
window$add(hbox)
vboxLoad = gtkVBoxNew(homogeneous = FALSE, spacing = 0)
vboxd$setSizeRequest(400,400)
hbox$add(vboxLoad)
scroll = gtkScrolledWindow()
vbox2 = gtkVBoxNew(homogeneous = FALSE, spacing = 0)
scroll$addWithViewport(vbox2)
vboxLoad$add(scroll)
framePlot = gtkFrameNew("Plot1")
framePlot2 = gtkFrameNew("Plot2")
vbox2$add(framePlot)
vbox2$add(framePlot2)
plot1 = gtkDrawingArea()
gtkWidgetSetSizeRequest(plot1,450,400)
asCairoDevice(plot1)
gtkWidgetShow(plot1)
framePlot$add(plot1)
plot2 = gtkDrawingArea()
gtkWidgetSetSizeRequest(plot2,450,400)
asCairoDevice(plot2)
gtkWidgetShow(plot2)
framePlot2$add(plot2)

Related

Add a title to gprofiler2 gosttable in R

Hello I'm a new bioinformatician so bear with me please!
I'm using the gprofiler2 to run GO/KEGG analysis in R using emacs/ess and I want to add a title to the table it offers:
publish_gosttable(gostres, highlight_terms = gostres$result[c(1:2,10,120),],
use_colors = TRUE,
show_columns = c("source", "term_name", "term_size", "intersection_size"),
filename = NULL)
I have tried the title(), tab_header() function but I can't seem to be able to add a title. My question is if there is some other function or package that would allow me to add it instead of having to do it manually.
The code so far
GOresult <- gost(
geneid1up$gene,
organism = "hsapiens",
ordered_query = FALSE,
multi_query = FALSE,
significant = TRUE,
exclude_iea = FALSE,
measure_underrepresentation = FALSE,
evcodes = FALSE,
user_threshold = 0.05,
correction_method = "gSCS",
domain_scope = "annotated",
custom_bg = NULL,
numeric_ns = "",
sources = c("GO:BP","GO:MF","GO:CC","KEGG"),
as_short_link = FALSE)
GOresult1 <- as.data.frame(GOresult$result)
GOresult1$minuslog10pval <- -log10(GOresult1$p_value)
names(GOresult1)[15] <- "-log10(pval)"
GOresult2 <- GOresult1[order(GOresult1$p_value, decreasing=F),]
plot1 <- publish_gosttable(GOresult2, highlight_terms = GOresult2[c(1:20),],
use_colors = FALSE,
show_columns = c("source", "term_name", "term_size", "intersection_size","-log10(pval)"),
filename = NULL)
Does this do the job?
library(gprofiler2)
library(ggplot2)
gostres <- gost(query = c("X:1000:1000000", "rs17396340", "GO:0005005", "ENSG00000156103", "NLRP1"),
organism = "hsapiens", ordered_query = FALSE,
multi_query = FALSE, significant = TRUE, exclude_iea = FALSE,
measure_underrepresentation = FALSE, evcodes = FALSE,
user_threshold = 0.05, correction_method = "g_SCS",
domain_scope = "annotated", custom_bg = NULL,
numeric_ns = "", sources = NULL, as_short_link = FALSE)
publish_gosttable(gostres, highlight_terms = gostres$result[c(1:2,10,120),],
use_colors = TRUE,
show_columns = c("source", "term_name", "term_size", "intersection_size"),
filename = NULL)+
ggtitle('Your Title')
Result:
The trick is that the plot is a ggplot objet. Therefore you can add the title using +ggtitle('Your Title') after your plot code (as in my example)

Adjusting distance from labels to table in grid.arrange in R

I cannot find how to adjust distance from labels to table in grid.arrange:
distances_lsit = c(25,50,75,100)
category_lsit = 0:5
damage_table = matrix(NA, nrow=length(distances_lsit), ncol=length(category_lsit))
damage_table[1,] = c(10,25,50,75,100,100)
damage_table[2,] = c(5,10,25,50,75,100)
damage_table[3,] = c(2.5,5,10,25,50,75)
damage_table[4,] = c(0,2.5,5,10,25,50)
rownames(damage_table) = distances_lsit
colnames(damage_table) = category_lsit
table_scale = tableGrob(damage_table)
grid.arrange(table_scale, top = "Label 1", left = "Label 2")
which produces table as follows:
Is there anyway to glue it to the table? Thank you in advance for your help.
You should play with next parameters for finding your best location
heights;
widths;
textGrob.
For example, this:
grid.arrange(table_scale, top = textGrob("Really looks \n better now?", x = 0, hjust = -1), left = "I'm near,\n my man", heights = c(2,1), widths = c(1,1.5))
show to you this:

Change the color of the bibliometric map in Packages

I'm having trouble changing the color of the bibliometric map using R. I intend to change the color to black and white. But I don't know the syntax used for that.
The code structure I use to generate the map looks like this:
conceptualStructure(M, field = "ID", method = "MCA", quali.supp = NULL, quanti.supp = NULL, minDegree = 2, clust = "auto", k.max = 5, stemming = FALSE, labelsize = 10, documents = 2, graph = TRUE)
Please help me, what code can I use to change the color of the map, background and text in my project.
I have never used conceptualStructure before, nor know what package it comes from (assuming it isn't base R), but I think you should be able to make it black and white by just specifying as such in the theme. E.g.
conceptualStructure(M,
field = "ID",
method = "MCA",
quali.supp = NULL,
quanti.supp = NULL,
minDegree = 2,
clust = "auto",
k.max = 5,
stemming = FALSE,
labelsize = 10,
documents = 2,
graph = TRUE) + theme_bw()
That may just be a ggplot2 thing though. In which case, i'm not sure I can help

PineScript (Tradingview) - I would like to see a line (Horizontal Ray) just below the candle instead of triangles

As in Title. I am trying to plot a horizontal radius below the body of the candle. At the moment when the triangles appear, I would like a horizontal ray pointing to the right.
Can anyone help me please? : d
Code:
//#version=4
study("attempt 1", overlay=true)
BarLow = low
BarHigh = high
BarOpen = open
BarClose = close
PreviousBarHigh = high[2]
PreviousBarLow = low[2]
PreviousBarOpen = open[2]
PreviousBarClose = close[2]
Drop = (BarHigh < PreviousBarOpen) and (BarOpen < PreviousBarOpen) and (BarClose < PreviousBarClose) and (PreviousBarLow > BarHigh)
Increase = (PreviousBarHigh < BarOpen) and (PreviousBarClose < BarOpen) and (PreviousBarHigh < BarLow)
plotshape(Increase, style = shape.triangleup, location = location.belowbar, color = color.green, size = size.tiny, offset=-2)
plotshape(Drop, style = shape.triangledown , location = location.abovebar, color = color.red, size = size.tiny, offset=-2)

How to switch active device with gWidgets tabbed notebook?

I have created a two-tab GUI with gWidgets. A graph is embedded in each of the two tabs. The problem is that both graphs are sent to tab 2. How can I switch or choose the active device? The vignette of the gwidgets package suggests either addHandlerChanged or ggraphicsnotebook. In using ggraphicsnotebook, some unwanted buttons are generated. So I am wondering how to do it with addHandlerChanged or other methods. A small example is attached. Thanks.
# library
library(gWidgets); library(cairoDevice)
options(guiToolkit = "RGtk2")
# first tab -----------------------------------------------------------
r.main <- gwindow(title = "Correlation", visible = TRUE)
r.nb <- gnotebook(container = r.main)
rSta <- ggroup(container = r.nb, horizontal = TRUE, label = "Static")
rDyn <- ggroup(container = r.nb, horizontal = FALSE, label = "Dynamic")
ggraphics(container = rSta)
obj.ptNum <- gradio(items = c("100", "1,000", "5,000"),
selected = 2, horizontal = FALSE, container = rSta,
handler = function(h, ...) {plot(1:10, main = "Static graph")})
# second tab -----------------------------------------------
obj.plotNum <- gradio(items = c("10", "50", "300", "400"),
selected = 2, horizontal = TRUE, container = rDyn,
handler = function(h, ...) {
plot(30:35, col = 'red', main = "Dynamic graph")})
ggraphics(container = rDyn)
Edit: I found one solution. Note the problem is not about selecting tab, but about selecting the current active embedded device. For future reference, my code is copied below. One small problem that I cannot figure out: how to show the graph when the application is launched without clicking? Thanks all.
library(gWidgets); library(cairoDevice); library(gWidgetsRGtk2)
library(RGtk2)
options(guiToolkit = "RGtk2")
# first tab -----------------------------------------------------------
r.main <- gwindow(title = "Correlation", visible = TRUE)
r.nb <- gnotebook(container = r.main)
rSta <- ggroup(container = r.nb, horizontal = TRUE, label = "Static")
ggraphics(container = rSta)
staPlot <- function(h, ...) {
sel <- ifelse(test = length(dev.list()) >= 2, yes = 2, no = 1)
dev.set(which = sel)
plot(1:as.numeric(svalue(obj.ptNum)), main = "Static graph")}
obj.ptNum <- gradio(items = c("100", "150", "200"),
selected = 2, horizontal = FALSE, container = rSta,
handler = staPlot)
# second tab -----------------------------------------------
rDyn <- ggroup(container = r.nb, horizontal = FALSE, label = "Dynamic")
dynPlot <- function(h, ...) {
sel <- ifelse(test = length(dev.list()) >= 2, yes = 3, no = 1)
dev.set(which = sel)
plot(1:as.numeric(svalue(obj.plotNum)), col = 'red',
main = "Dynamic graph")}
obj.plotNum <- gradio(items = c("10", "50", "300", "400"),
selected = 2, horizontal = TRUE, container = rDyn,
handler = dynPlot)
ggraphics(container = rDyn)
svalue(r.nb) <- 1
It's bad to use dev.set. If you to create a plot in a graphics device, you can use the following code.
graph <- ggraphics()
visible(graph) <- TRUE
boxplot(...)

Resources