Create Box & Whisker Plots with Overlay of Individual Data Points in SPSS - boxplot

I'm unable to find a way to create in SPSS a box & whisker plot with individual data points overlaid upon it like this:
I.e., similar to what one could achieve in R via the geom_jitter() function in the ggplot2 package, as described in this post, but with SPSS--preferably via Syntax. Is this possible?

I don't think you can do this via the dialog boxes, but you can do it using the GGRAPH command and GPL (Graphics Programming Language). Here's an example. Open the Employee.sav file that comes installed with SPSS Statistics, open a syntax window and paste these commands in, then click Run>All:
GGRAPH
/GRAPHDATASET NAME="Employeedata" VARIABLES=jobcat salary
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s = userSource(id("Employeedata"))
DATA: jobcat = col(source(s), name("jobcat"), unit.category())
DATA: salary = col(source(s), name("salary"))
GUIDE: axis(dim(2), label("Current Salary"))
GUIDE: axis(dim(1), label("Job Category"))
GUIDE: form.line(position(*, 25000))
SCALE: linear(dim(2), include(0))
ELEMENT: schema(position(bin.quantile.letter(jobcat*salary)))
ELEMENT: point.dodge.symmetric(position(bin.dot(jobcat*salary,dim(2))),color(color.red))
END GPL.
I've included a reference line here, as is also in the original image.

Related

Exporting figures programmatically (R2019a)

In MATLAB R2019a a new way to export figures was added whereby the result "is tightly cropped around the axes with minimal white space". This feature is accessed using the axes toolbar:
My question is: How do we invoke this new export feature programmatically?
It should be fairly easy to get the export dialog to open for specific axes (i.e. simulate a button click), but I'm more interested in bypassing the dialog and just saving a file to disk, e.g.
croppedExport(hAxes, outputPath);
P.S.
I am aware that this functionality can be achieved using a 3rd party tool like export_fig.
TL;DR
matlab.graphics.internal.export.exportTo(hAxes, fullpath);
The tooltip of this new button says "Export...", which is going to help us identify it. Digging within the properties of the axes toolbar (struct(hAxes.Toolbar)) we can get a glimpse of the function that is being called when the button is pressed:
hB = struct(struct(hAxes.Toolbar).ButtonGroup).NodeChildren(1);
%{
hB =
ToolbarPushButton (Export...) with properties:
Tooltip: 'Export...'
Icon: 'export'
ButtonPushedFcn: #(e,d)matlab.graphics.internal.export.exportCallback(d.Axes)
%}
which unfortunately points to directory full of .p files:
...\MATLAB\R2019a\toolbox\matlab\graphics\+matlab\+graphics\+internal\+export
...and forces us to do proceed with trial and error. For example, we can choose a random .p file whose name sounds right to us, and see if we can discover its API:
>> matlab.graphics.internal.export.exportTo()
Error using matlab.graphics.internal.export.exportTo
Not enough input arguments.
>> matlab.graphics.internal.export.exportTo('')
Error using matlab.graphics.internal.export.exportTo
Not enough input arguments.
>> matlab.graphics.internal.export.exportTo('','')
Error using matlab.graphics.internal.export.ExporterArgumentParser/parseInputParams
'' matches multiple parameter names: 'background', 'destination', 'format', 'handle', 'margins', 'resolution', 'target'. To avoid ambiguity, specify the complete name of the parameter.
Error in matlab.graphics.internal.export.ExporterArgumentParser/processArguments
Error in matlab.graphics.internal.export.Exporter/process
Error in matlab.graphics.internal.export.exportTo
The last error message provides very interesting information, which allows us to take some educated guesses regarding the required inputs:
'background' - probably background color
'destination' - probably where to put the file
'format' - probably what is the file extension
'handle' - probably the axes handle
'margins' - (self explanatory)
'resolution' - (self explanatory)
'target' - ???
Following the "minimal" input set that is requested in the question, our next attempt is:
membrane;
matlab.graphics.internal.export.exportTo('handle', gca, 'destination', 'e:\blabla.png');
... which creates the a file at the desired location and also returns a truecolor RGB image that is cropped just like we wanted!
Although we are done, we can try to simplify this function call even further based on the "convention" of saveas, which is saveas(what, where, ...):
matlab.graphics.internal.export.exportTo(gca, 'e:\blabla.png');
... which works (!) and so this becomes our method of choice.

How do I find more comprehensive Google Documentation for using its APIs

A lot of the times the Google documentation is incomplete and is missing things like libraries required to import. How do I view a more comprehensive example?
Example: https://cloud.google.com/vision/docs/detecting-faces#vision-face-detection-python
def highlight_faces(image, faces, output_filename):
"""Draws a polygon around the faces, then saves to output_filename.
Args:
image: a file containing the image with the faces.
faces: a list of faces found in the file. This should be in the format
returned by the Vision API.
output_filename: the name of the image file to be created, where the
faces have polygons drawn around them.
"""
im = Image.open(image)
draw = ImageDraw.Draw(im)
for face in faces:
box = [(vertex.x, vertex.y)
for vertex in face.bounding_poly.vertices]
draw.line(box + [box[0]], width=5, fill='#00ff00')
im.save(output_filename)
Missing the PIL import
On many of Google's code examples, there will be a VIEW ON GITHUB button that will take you to a complete working example rather than a snippet. Very useful for finding necessary library imports or just going straight to more code.
When that is missing, sometimes there is a link to the file like this firebase example linking to index.js:

How can I create in Gehpi directed tree graph instead of sphererical

I want to make a network graph which shows the distribution of our documents in our folder structure.
I have the nodefile, edgefile and gephi graph file in this location:
https://1drv.ms/f/s!AuVfRBdVHkO7hgs5K9r9f7jBBAUH
What I do is:
Run the algorithm ForceAtlas2 with scaling 10-20, dissuade hub marked and prevent overlap marked, all other standard setting.
What I get is a graph with groups radial/spherical distributed. However, what I want is a tree directed network graph.
Anyone know how I can adjust Gephi to make this?
Thanks!
I just found a solution.
I tested the file format as shown on the Yed site "import excel file" page
http://yed.yworks.com/support/manual/import_excel.html
This gave me the Yed import dialog (took a life time to figure out that it's a pop up menu and not selectable through the standard menu)
Anyway, it worked and I've adjusted the test files with the data prepared for the Gehpi. This was pretty easy, I could used the source target ID's etc. Just copy paste.
I load it into Yed and used some directed and radial clustering algorithms on it. Works fine!
Below you can find the excel node/edge file used to import in Yed and the graph file you can open with Yed to see the final radial result.
https://1drv.ms/f/s!AuVfRBdVHkO7hg6DExK_eVkm5_mR
Only thing to figure out is how to combine the weight (which represents the number of documents) with the node size.
Unfortunately, as of version 0.9.0, Gephi no longer supports hierarchical graphs. Maybe try using a previous version?
Other alternatives involve more complex software, such as Graphviz, but you need a .dot file instead of your .csv. I looked all over, but could not find an easy-to-use csv to dot converter.
You could try looking at d3-hierarchy, a node.js program, but then again you need to use the not-so-user-friendly npm. If you look at the link, it looks like it can produce the kind of diagram you're looking for.

In MATLAB, define and color different regions of a shapefile

I have downloaded a shapefile that shows different regions (Identifiers) on a map (Equatorial, Tropical, Subtropical, Desert, Grassland, Temperate) according to the readme.txt file that came with it.
my_map = shaperead('my_shape_file.shp');
mapshow(my_map)
How do I define the different regions to enable me to color code them? I don't know how they are defined in the shapefile. The readme.txt file says "The identifiers are shown in the field titled Grid-code." I was expecting something like this to work:
zones = {my_map.Grid-code};
or
zone1 = {my_map.Tropical};
Please help! Thanks.

LaTeX math in github wikis

Is it possible to include LaTeX-style math in any way with github repo wikis? Googling implies github no longer allows things like MathJax, but most references are years old. What (if any) alternatives are there to including LaTeX-formatted math in github wikis?
You can use chart.apis.google.com to render LaTeX formulas as PNG.
It work nicely with Githhub's markdown:
Example (Markdown):
The ratio of the momentum to the velocity is
the relativistic mass, m.
![f1]
And the relativistic mass and the relativistic
kinetic energy are related by the formula:
![f2]
Einstein wanted to omit the unnatural second term
on the right-hand side, whose only purpose is
to make the energy at rest zero, and to declare
that the particle has a total energy, which obeys:
![f3] which is a sum of the rest energy ![f4]
and the kinetic energy.
[f1]: http://chart.apis.google.com/chart?cht=tx&chl=m=\frac{m_0}{\sqrt{1-{\frac{v^2}{c^2}}}}
[f2]: http://chart.apis.google.com/chart?cht=tx&chl=E_k=mc^2-m_0c^2
[f3]: http://chart.apis.google.com/chart?cht=tx&chl=E=mc^2
[f4]: http://chart.apis.google.com/chart?cht=tx&chl=m_0c^2
https
Some installations of Github Enterprise reject http and work only if you use https
Rendered:
For simple formulas (such as exponents etc) you may one just to use the available render languages. For example, using Textile, you can do:
_E = mc ^2^_
Thiw will be rendered as:
_ is used for italic style and ^ for superscript.
You can do the same thing in Markdown adding some HTML:
*E = mc<sup>2</sup>*
You can see it in action in this very place:
E = mc2
If you're looking for support for complex math formulas, then you have no better option than using a third-party service generating images for you. mathUrl looks interesting.
As input we give it E = mc ^ 2 and it generates the following link:
http://mathurl.com/render.cgi?E%20%3D%20mc%20%5E%202%5Cnocache
There is good solution for your problem - use TeXify github plugin - more details about this plugin and explanation why this is good approach you can find in that answer.
GitLab Wiki and markdown supports formulas. I moved multiple repos for this reason.
Now GitHub officially supports showing Mathjax in the wiki!
In Markdown, just use $ as the deliminator of inline formulas, and $$ as the deliminator of display formulas.
To add math equations to a GitHub wiki, I used mathURL as suggested by Ionică. It will render your LaTeX equations. Append .png to the generated url and use that url as an image (either block or inline) in your markdown.