Using axis ranges to place labels at arbitrary category - amcharts4

As you can see in the below image. I want to add custom label ranges for y axis.
I have followed this tutorial and tried below code but it was not working, Any idea how to use categoryAxis with custom labels?
let range0 = categoryAxis.axisRanges.create();
range0.value = "MCR.INV-1";
range0.text = "MCR.INV-1";
let range500 = categoryAxis.axisRanges.create();
range500.value = "MCR.INV-2";
range500.text = "MCR.INV-2";
let range1000 = categoryAxis.axisRanges.create();
range1000.value = "PEV1.INV-1";
range1000.text = "PEV1.INV-1";

CategoryAxis ranges use category/endCategory for placement. Replacing value with category in your ranges will fix the problem.

Related

Shiny - dygraphs: Show all error-bar values in legend

I am using dygraphs for R and I opened the following issue on GitHub the other day, however, I have not yet received an answer. Therefore, I am hoping someone in here will be able to answer my question.
I want to know if it is possible to show all the values of the prediction interval in the legend, i.e. , lower, actual, upper, without having them as three separate plain dySeries? I like the look of the shading that the upper/lower bars bring, but I would also like to be able to hover over a point and see all the values for that particular point, not just the middle one. If such a function does not exists, is there an easy workaround, maybe with fillGraph = TRUE or something?
library(dygraphs)
hw <- HoltWinters(ldeaths)
p <- predict(hw, n.ahead = 72, prediction.interval = TRUE)
dygraph(p, main = "Predicted Lung Deaths (UK)") %>%
dySeries(c("lwr", "fit", "upr"), label = "Deaths")
The preceding code is the example from the web page, which is similar to my problem. I simply want to see the lwr and upr values in the legend when hovering.
So I found a workaround for anybody looking for something similar.
library(dygraphs)
hw <- HoltWinters(ldeaths)
p <- predict(hw, n.ahead = 72, prediction.interval = TRUE)
max <- p[,2]
min <- p[,3]
p <- ts.union(p, max, min)
dygraph(p, main = "Predicted Lung Deaths (UK)") %>%
dySeries(c("p.lwr", "p.fit", "p.upr"), label = "Deaths") %>%
dySeries("max", label = "Max", pointSize = 0.01, strokeWidth = 0.001) %>%
dySeries("min", label = "Max", pointSize = 0.01, strokeWidth = 0.001)
Obviously, this can be modified to suit your needs (e.g. color of the points etc.) The main idea in this method is simply to create two new columns containing the same information that is used in the bands, and then to make the lines to these too small to see.

How to use UIMotionEffect in SwiftUI?

Any idea how to use UIMotionEffect in SwiftUI? I was thinking there might be a way to connect the motion effect to a state variable and then using that variable in SwiftUI we get a similar result to UIKit.
Simple UIKit example
let value = 12
let verticalMotionEffect = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.y", type: .tiltAlongVerticalAxis)
verticalMotionEffect.minimumRelativeValue = value
verticalMotionEffect.maximumRelativeValue = -value
let horizontalMotionEffect = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.x", type: .tiltAlongHorizontalAxis)
horizontalMotionEffect.minimumRelativeValue = value
horizontalMotionEffect.maximumRelativeValue = -value
let group = UIMotionEffectGroup()
group.motionEffects = [horizontalMotionEffect, verticalMotionEffect]
view.addMotionEffect(group)

Control legend colors in tactile::bwplot2

In this reproducible example below with the tactile package, the colors are automatically chosen for the boxplots and corresponding legend. However, I would like to customize the colors of the boxplots and legend.
tactile::bwplot2(runif(1000) ~ cut(runif(1000), c(0,0.3,0.6,1)) | as.factor(c(1,2,3)),
groups = sample(1:2, 1000, replace = TRUE), auto.key = TRUE)
However, when I tried to do this, the colors in the boxplots changed but the legend colors did not:
Here I create a new color scheme:
coolNewPars <- list(superpose.symbol = list(pch = 21, cex = 2, col = "gray20",
fill = continentColors$color))
And then plot the boxplots again, with auto.key instructed to place the legend contents into 2 columns and the par.settings set to coolNewPars:
tactile::bwplot2(runif(1000) ~ cut(runif(1000), c(0,0.3,0.6,1)) | as.factor(c(1,2,3)),
groups = sample(1:2, 1000, replace = TRUE), auto.key = list(columns = 2),par.settings = coolNewPars)
How do I force the legend colors to match the coolNewPars colors?
The problem is that lattice::panel.superpose() uses trellis.get.par("superpose.symbol") to differentiate between groups, whilst
the function that draws the key uses "superpose.polygon", or something like it.
In any case, here is a solution (although it is awkward):
coolNewPars <- list(superpose.polygon = list(col = 2:3),
superpose.symbol = list(fill = 2:3))
tactile::bwplot2(runif(1000) ~ cut(runif(1000), c(0,0.3,0.6,1)) | as.factor(c(1,2,3)),
groups = sample(1:2, 1000, replace = TRUE),
auto.key = TRUE,
par.settings = coolNewPars)

How to resize tables generated by Stargazer in R Markdown?

I included resize.height=0.5,resize.width=0.5 in the code chunk, but still can't resize the table generated by stargazer. Can anyone tell me why?
My code chunk options look like this:
echo=FALSE,warning=FALSE,results='asis',resize.height=0.5,resize.width=0.5}
The stargazer codes are like this:
stargazer(did.student,student.control.kmt,student.control.neu,student.control.dpp,header = FALSE,
title="DD Model",
covariate.labels = c("Treatment","group","Treatment*group"),
dep.var.labels = "attitude",
column.labels = c("","party1","Independent","party2"),
label = "DiD-students")
Would appreciate any help!
--
Forgot to mention - I'm using beamer with the table.
I kind of solve the problem myself:
To adjust table size with stargazer, you can change the font size font.size=, make the Stargazer single row single.row = TRUE and change the space between columns column.sep.width = "1pt" in stargazer().
Though the link here suggests using print(stargazer(),scalebox='0.7'), it doesn't work for me perhaps because I'm using Markdown with Beamer, but I'm not sure. Would still love to have more contribution on this.
I was hoping for a more straightforward answer, but this works!
This comment on GitHub inspired me to implement \resizebox{} into stargazer(). You can use resizebox.stargazer() to specify the size of the table outputted from stargazer() with tab.width and/or tab.height arguments. To activate the function, you need to run the following code first:
resizebox.stargazer = function(..., tab.width = "!", tab.height = "!"
){
#Activate str_which() function:
require(stringr)
#Extract the code returned from stargazer()
res = capture.output(
stargazer::stargazer(...)
)
#Render the arguments:
tab.width = tab.width
tab.height = tab.height
#Attach "}" between \end{tabular} and \end{table}
res =
prepend(res, "}", before = length(res))
#Input \resizebox before \begin{tabular}
res =
c(res[1:str_which(res, "^\\\\begin\\{tabular\\}.*")-1],
paste0("\\resizebox{",tab.width,"}{",tab.height,"}{%"),
res[str_which(res, "^\\\\begin\\{tabular\\}.*"):length(res)]
)
#Produce the whole strings
cat(res, sep = "\n")
}
You can specify the table size by e.g. resizebox.stargazer(..., tab.width = "0.7\\textwidth"). Note that you have to write the TeX commands from \\ instead of \.
I would follow #yuan-ning and manipulate the options of stargazer. Try the following for PDF output of R markdown:
stargazer(model_1, model_2, model_3, model_4, model_5,
type = 'latex',
header=FALSE, # to get rid of r package output text
single.row = TRUE, # to put coefficients and standard errors on same line
no.space = TRUE, # to remove the spaces after each line of coefficients
column.sep.width = "3pt", # to reduce column width
font.size = "small" # to make font size smaller
)
Here is an alternative to Carlos' solution that writes the output to a LaTeX file:
mkTexTable <- function(..., file){
tbl <- capture.output({
stargazer(...)
})
tbl <- gsub("\\begin{tabular}", "\\resizebox{\\textwidth}{!}{\\begin{tabular}", tbl, fixed = T)
tbl <- gsub("\\end{tabular}", "\\end{tabular}}", tbl, fixed = T)
fileConn <- file(file)
writeLines(tbl, fileConn)
close(fileConn)
}
mkTexTable(lm1, lm2, "texOutput.tex")
This post also provided some help: https://stackoverflow.com/a/36018251/2289444
If the problem is with html Rmd files, you sould specify {r, results = 'asis'} at the beginning of the chunck and then in stargazer type = 'html'. That worked for me.

Raphael: Inherited transformations

Based on another thread (Raphaeljs transformations with sets)
I have played around with inherited transformations using sets in sets.
I tried to put a set in another set and each set would apply a 45° rotation. I expected, that both rotation would sum up to a 90° rotation. That is working fine.
But both rotations are relative to the centerpoint of each single Object in the Set. How can I achieve, that the rotations are relative to the center point of the Set? Is this possible?
To clarify what I mean. If I have two rectangles in a set and I apply a rotation on the set, I want that the rectangles will stay in the same position and angle relative to them self, because they both rotate around an axis that is between them, in the middle of the set. So they must be translated additionally to the rotation...
how can I achieve this?
jsfiddle:http://jsfiddle.net/bBy9b/
var paper = Raphael(0,0,500,500);
var a = paper.rect(10,10,50,10);
var b = paper.rect(10,30,50,10)
var c = paper.rect(10,50,50,10);
var d = paper.rect(10,70,50,10);
var set = paper.set()
set.push(a);
set.transform("r-45");
var rootSet = paper.set();
rootSet.push(set, b, c);
rootSet.transform("...r-45");
Thx for your help in advance!
The r command takes two additional optional parameters which are the centre point of the rotation. So it looks like you want something like this:
window.onload = function(){
var paper = Raphael(0,0,500,500);
var a = paper.rect(10,10,50,10);
var b = paper.rect(10,30,50,10)
var c = paper.rect(10,50,50,10);
var d = paper.rect(10,70,50,10);
var set = paper.set()
set.push(a);
set.transform("...r-45,40,45");
var rootSet = paper.set();
rootSet.push(set, b, c);
rootSet.transform("...r-45,40,45");
}