Control edge with neato layout with processmapR - r

I'm using the bupaR process mining suite and processmapR to plot my log as a process map but when I try to set a custom position (which force the graph to use a neato layout) the edge become almost staight and the edge value hard to read:
Default graph with no custom position:
With custom position:
I tried to use
positions <- data.frame(act = c("node1","node2","node 3","node 4","node 5","Start", "End"),
y = c(5,4,3,2,1,6,0),
x = c(1,2,3,4,5,0,6),
stringsAsFactors = F)
graph = process_map(log, fixed_node_pos = positions, render = F)
map = add_global_graph_attrs(graph,
attr = "splines",
value = "true",
attr_type = "graph")
render_graph(map)
But I could not find any attribute to change the way edge are displayed, like adding more curve to them
How can I fix this problem ?
Thanks

Try the following:
map = add_global_graph_attrs(graph,
attr = "splines",
value = "curved",
attr_type = "graph")

Related

Plot title with variable value and subscript characters in Julia

I'm trying to have a plot title which contains variable values and also characters with subscripts, however when I try:
title = "ηₛ = $η̂[Pa S] , μₛ = $μ̂[Pa], μₚ = $μ̂ₚ[Pa] , ηₚ = $η̂ₚ[Pa S] \n α = $α̂ , ζ = $ζ̂"
Inside the plot function, the title appears with X marks where the subscripts are. I tried to use LaTeX ```title = L" .." but then the variable values don't appear.
Is there any way to have both in the title I need?
If you want a fully working solution this is what I think you need to do, note that %$ is used for interpolation:
title = L"\eta_1 = %$(η̂[Pa, S])"
The reason is that, while some of the characters will be rendered correctly as Bill noted, not all of them will unless you use LaTeXStrings.jl.
See:
help?> LaTeXStrings.#L_str
L"..."
Creates a LaTeXString and is equivalent to latexstring(raw"..."), except that %$ can be used for interpolation.
julia> L"x = \sqrt{2}"
L"$x = \sqrt{2}$"
julia> L"x = %$(sqrt(2))"
L"$x = 1.4142135623730951$"

Julia: "Plot not defined" when attempting to add slider bars

I am learning how to create plots with slider bars. Here is my code based off the first example of this tutorial
using Plots
gr()
using GLMakie
function plotLaneEmden(log_delta_xi=-4, n=3)
fig = Figure()
ax = Axis(fig[1, 1])
sl_x = Slider(fig[2, 1], range = 0:0.01:4.99, startvalue = 3)
sl_y = Slider(fig[1, 2], range = -6:0.01:0.1, horizontal = false, startvalue = -2)
point = lift(sl_x.value, sl_y.value) do n, log_delta_xi
Point2f(n, log_delta_xi)
end
plot(n, 1 .- log_delta_xi.^2/6, linecolor = :green, label="n = $n")
xlabel!("ξ")
ylabel!("θ")
end
plotLaneEmden()
When I run this, it gives UndefVarError: plot not defined. What am I missing here?
It looks like you are trying to mix and match Plots.jl and Makie.jl. Specifically, the example from your link is entirely for Makie (specifically, with the GLMakie backend), while the the plot function you are trying to add uses syntax specific to the Plots.jl version of plot (specifically including linecolor and label keyword arguments).
Plots.jl and Makie.jl are two separate and unrelated plotting libraries, so you have to pick one and stick with it. Since both libraries export some of the same function names, using both at once will lead to ambiguity and UndefVarErrors if not disambiguated.
The other potential problem is that it looks like you are trying to make a line plot with only a single x and y value (n and log_delta_xi are both single numbers in your code as written). If that's what you want, you'll need a scatter plot instead of a line plot; and if that's not what you want you'll need to make those variables vectors instead somehow.
Depending on what exactly you want, you might try something more along the lines of (in a new session, using only Makie and not Plots):
using GLMakie
function plotLaneEmden(log_delta_xi=-4, n=3)
fig = Figure()
ax = Axis(fig[1, 1], xlabel="ξ", ylabel="θ")
sl_x = Slider(fig[2, 1], range = 0:0.01:4.99, startvalue = n)
sl_y = Slider(fig[1, 2], range = -6:0.01:0.1, horizontal = false, startvalue = log_delta_xi)
point = lift(sl_x.value, sl_y.value) do n, log_delta_xi
Point2f(n, 1 - log_delta_xi^2/6)
end
sca = scatter!(point, color = :green, markersize = 20)
axislegend(ax, [sca], ["n = $n"])
fig
end
plotLaneEmden()
Or, below, a simple example for interactively plotting a line rather than a point:
using GLMakie
function quadraticsliders(x=-5:0.01:5)
fig = Figure()
ax = Axis(fig[1, 1], xlabel="X", ylabel="Y")
sl_a = Slider(fig[2, 1], range = -3:0.01:3, startvalue = 0.)
sl_b = Slider(fig[1, 2], range = -3:0.01:3, horizontal = false, startvalue = 0.)
points = lift(sl_a.value, sl_b.value) do a, b
Point2f.(x, a.*x.^2 .+ b.*x)
end
l = lines!(points, color = :blue)
onany((a,b)->axislegend(ax, [l], ["$(a)x² + $(b)x"]), sl_a.value, sl_b.value)
limits!(ax, minimum(x), maximum(x), -10, 10)
fig
end
quadraticsliders()
ETA: A couple examples closer to what you might be looking for

DiagrammeR: Force horizontal arrows to be straight rather than diagonal

I am attempting to recreate this example as a test for a flow diagram for a project I am working on: https://dannyjnwong.github.io/STROBE-CONSORT-Diagrams-in-R/
That page shows the code should result in a diagram that looks like this: https://dannyjnwong.github.io/figures/2018-02-12-STROBE-CONSORT-Diagrams-in-R/STROBE.png
However, when I try running the same exact code in RStudio I get this instead, the horizontal arrows do not render as horizontal, they instead curve downwards:
Is there any way to force these arrows to be straight and horizontal as they are in the github example? Could it perhaps be related to the version of DiagrammeR? That post uses DiagrammeR_0.9.2 while mine is using DiagrammeR_1.0.6.1 I would like to avoid having to roll back my version of the package if possible. Thanks!
I use ortho splines with DiagrammeR to get horizontal lines in my flowcharts. I tried using add_global_graph_attrs with create_graph in your example which produced horizontal lines but did not keep the architecture intact.
Here is how I have made similar graphs. I use glue for convenience to insert specific values and text in the flowchart. Perhaps this may be helpful for you.
library(DiagrammeR)
library(glue)
n <- 1000
exclude1 <- 100
exclude2 <- 50
include1 <- n - exclude1 - exclude2
grViz(
glue("digraph my_flowchart {{
graph[splines = ortho]
node [fontname = Helvetica, shape = box, width = 4, height = 1]
node1[label = <Total available patients<br/>(n = {n})>]
blank1[label = '', width = 0.01, height = 0.01]
excluded1[label = <Excluded because of<br/>exclusion criteria (n={exclude1})>]
node1 -> blank1[dir = none];
blank1 -> excluded1[minlen = 2];
{{ rank = same; blank1 excluded1 }}
blank2[label = '', width = 0.01, height = 0.01]
excluded2[label = <Excluded because of missing values (n={exclude2})>]
blank1 -> blank2[dir = none];
blank2 -> excluded2[minlen = 2];
{{ rank = same; blank2 excluded2 }}
node2[label = <Included for analysis<br/>(n={include1})>]
blank2 -> node2;
node3[label = <Data linked with<br/>external dataset>]
node2 -> node3;
}}")
)
Note: a couple of efforts have been made to construct CONSORT diagrams:
https://github.com/higgi13425/ggconsort
https://github.com/tgerke/ggconsort
Diagram

Change tooltip values based on Holoviews dropdown

I am trying to dynamically modify my y-axis tick formatting and tooltip formatting based on what is selected in a Holoviews dropdown. I figured I could do this in finalize_hooks. Since I don't know how to test for what has been selected in the dropdown, I used the title value to determine that. This seems to work ok though I am sure there could be a more elegant solution that I am not aware of. Also, I am able to change the tick formatter but the hover value doesn't change based on the above method. See example code below. Tooltip always shows Value1, never Value 2 no matter which country I select. Please advise if there is a way to fix this.
%%opts Bars [show_grid=True width=1400 height=400 xrotation=0] {+framewise}
macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\t')
key_dimensions = [('year', 'Year'), ('country', 'Country')]
value_dimensions = [('unem', 'Unemployment'), ('capmob', 'Capital Mobility'),
('gdp', 'GDP Growth'), ('trade', 'Trade')]
macro = hv.Table(macro_df, key_dimensions, value_dimensions)
hover = HoverTool(tooltips=[('year', '#year'),
('Value', '#unem{0.000%}')])
def apply_formatter(plot, element):
p = plot.handles['plot']
if 'Austria' in p.title.text:
plot.handles['yaxis'].formatter = NumeralTickFormatter(format="0")
p.hover[0].tooltips[1] = ('Value1', '#unem{0.0%}')
else:
plot.handles['yaxis'].formatter = NumeralTickFormatter(format="0.0%")
p.hover[0].tooltips[1] = ('Value2', '#unem{0.00%}')
bars = macro.to(hv.Bars, kdims='year', vdims=['unem']).opts(plot=dict(tools=[hover], finalize_hooks=[apply_formatter]))
bars
This seems to work
from bokeh.models import NumeralTickFormatter
from bokeh.models import HoverTool
macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\t')
key_dimensions = [('year', 'Year'), ('country', 'Country')]
value_dimensions = [('unem', 'Unemployment'), ('capmob', 'Capital Mobility'),
('gdp', 'GDP Growth'), ('trade', 'Trade')]
macro = hv.Table(macro_df, key_dimensions, value_dimensions)
def apply_formatter(plot, element):
p = plot.state
global x
x = p
if 'Austria' in p.title.text:
plot.handles['yaxis'].formatter = NumeralTickFormatter(format="0")
hover = HoverTool(tooltips=[('year', '#year'),
('Value', '#unem{0%}')])
p.tools = [hover]
else:
plot.handles['yaxis'].formatter = NumeralTickFormatter(format="0.0%")
hover = HoverTool(tooltips=[('year', '#year'),
('Value', '#unem{0.00%}')])
p.tools = [hover]
bars = macro.to(hv.Bars, kdims='year', vdims=['unem']).options(
tools=[], finalize_hooks=[apply_formatter])
bars

Control size of the output of seqLogo?

I am using the seqLogo package to draw some sequence Logos. I need to make the logos wider, the default drawing makes the logos into square graphs. Is there a way to do this?
You can view the code from seqLogo:
> library(seqLogo)
> seqLogo
function (pwm, ic.scale = TRUE, xaxis = TRUE, yaxis = TRUE, xfontsize = 15, yfontsize = 15)
{
if (class(pwm) == "pwm") {
pwm <- pwm#pwm
}
...
}
<environment: namespace:seqLogo>
>
There are parameters in there that control rendering, which you could adjust by editing the function code. See this SO answer to learn about the fix() function.

Resources