I created a line diagram with multiple lines with the Chart Builder in SPSS.
Within the Chart Editor I changed the line style from "color" to "dash". I saved the style as a template to apply it to further similar line charts. However the template doesn't seem to be applied, the lines are still colored and not dashed.
Is there a way to tell SPSS in the Syntax to apply a dashed line style from template?
Yes, you have to tell SPSS inside the GPL statement that you want to use a dashed style.
So lets assume you created the following chart from the 'breakfast.sav' sample file:
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=BT COUNT()[name="COUNT"]
gender[LEVEL=NOMINAL] MISSING=LISTWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE TEMPLATE = "$HOME/SPSS/linediagram.sgt".
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: BT=col(source(s), name("BT"), unit.category())
DATA: COUNT=col(source(s), name("COUNT"))
DATA: gender=col(source(s), name("gender"), unit.category())
GUIDE: axis(dim(1), label("Buttered toast"))
GUIDE: axis(dim(2), label("Percent"))
GUIDE: legend(aesthetic(aesthetic.color.interior), label("Gender"))
SCALE: linear(dim(2), include(0))
SCALE: cat(aesthetic(aesthetic.color.interior), include("1", "2"))
ELEMENT: line(position(summary.percent(BT*COUNT,
base.aesthetic(aesthetic(aesthetic.color.interior)))),
color.interior(gender), missing.wings())
END GPL.
Now within the ELEMENT statement you need to change both color.interior functions into shape.interior. So the statement would look like this.
ELEMENT: line(position(summary.percent(BT*COUNT,
base.aesthetic(aesthetic(aesthetic.shape.interior)))),
shape.interior(gender), missing.wings())
This turns the colored lines into black dashed lines.
If you want colored and dashed lines, just add the shape.interior(gender) function to the existing ELEMENT statement:
ELEMENT: line(position(summary.percent(BT*COUNT,
base.aesthetic(aesthetic(aesthetic.color.interior)))),
color.interior(gender), shape.interior(gender), missing.wings())
I thought the point was to add these settings. But if you don't want them, just delete the aesthetic, color, and shape function references.
Related
I am trying to make the tool tip 'Percentage' be an actual percent and not a decimal. Even when I include alt.Tooltip('Percentage:Q',format='.2%'), it doesn't seem to work.
Also, I am trying to make the legend scale from 0-100% instead of 40-70%.
Any help would be appreciated!
import altair as alt
from vega_datasets import data
states = alt.topo_feature(data.us_10m.url, 'states')
variable_list = ['Percentage', 'State Name', 'state_id']
alt.Chart(states).mark_geoshape().encode(
color=alt.Color('Percentage:Q', title='Positive NFB', legend=alt.Legend(format=".0%"), scale=alt.Scale(scheme='yellowgreen')),
tooltip=['State Name:N', 'Percentage:Q', alt.Tooltip('Percentage:Q',format='.2%')]).properties(title="Percentage of People in Households with Positive NFB"
).transform_lookup(
lookup='id',
from_=alt.LookupData(states_positive_NFB, 'state_id', variable_list)
).properties(
width=500,
height=300
).project(
type='albersUsa'
)
Current map:
To change the domain of the color scale, you can pass the domain argument to alt.Scale(): e.g.
alt.Scale(scheme='yellowgreen', domain=[0, 1])
To make the tooltip format appear, you can remove the duplicated tooltip encoding, as the first one appears to be taking precedence. That is, rather than
tooltip=['State Name:N', 'Percentage:Q', alt.Tooltip('Percentage:Q',format='.2%')]
you should use
tooltip=['State Name:N', alt.Tooltip('Percentage:Q', format='.2%')]
With SPSS v.25, I'm trying to add (via syntax) descriptive text a histogram's descriptive stats. So in the area of the graph that shows the Mean, Std. Dev, and N, is there a way to add text (again, via syntax)? Here's where I'm at:
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=TS_Pre_Raw_Sq_21 TS_Post_Raw_Sq_22 MISSING=LISTWISE
REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: TS_Pre_Raw_Sq_21=col(source(s), name("TS_Pre_Raw_Sq_21"))
DATA: TS_Post_Raw_Sq_22=col(source(s), name("TS_Post_Raw_Sq_22"))
GUIDE: axis(dim(1), label("Team STEPPS Pre-Test Raw Score 2018 Fall"))
GUIDE: axis(dim(2), label("Frequency"))
GUIDE: text.title(label("Team STEPPS Analysis"))
GUIDE: text.subtitle(label("Insert Term Here; e.g, Fall 2018"))
GUIDE: text.subsubtitle(label("Insert Cohort"))
GUIDE: text.footnote(label("Pre Test: Green Post Test: Blue"))
GUIDE: legend(aesthetic(aesthetic.color), label("Gender"))
ELEMENT: interval(position(summary.count(bin.rect(TS_Pre_Raw_Sq_21))),
shape.interior(shape.square), color(color.green), transparency.interior(Transparency. "0.6")))
ELEMENT: interval(position(summary.count(bin.rect(TS_Post_Raw_Sq_22))),
shape.interior(shape.square)), color(color.blue), transparency.interior(Transparency. "0.8")))
ELEMENT: line(position(density.normal(TS_Pre_Raw_Sq_21)))
ELEMENT: line(position(density.normal(TS_Post_Raw_Sq_22)))
END GPL.
And this is what I get:
So I have forced distributions from two variables in the graph but the descriptive stats aren't labeled; I'd like to add be able to show which stats correspond to which distributions.
Thanks in advance!
This is the test code im using
x_coord <- c(1,2,3,4)
y_coord <- c(1,2,3,4)
value <- c(12,15,19,30)
foo <- data.frame(x_coord, y_coord, value)
library(MBA)
foo=foo[ order(foo[,1], foo[,2],foo[,3]), ]
mba.int <- mba.surf(foo, 300, 300, extend=T)$xyz.est
library(fields)
fields::image.plot(mba.int,legend.only = FALSE, axes=FALSE)
The axes part deletes the axis, but when i try to remove the legend bar, the vertical bar indicating the color measurements, it will not go away.
i have tried smallplot = 1, but that gives me an error but it gets rid of the vertical legend,
Anyone have any idea of how to get rid of the legend without any errors produced ?
If you don't want the color legend, just use the built-in image function instead. The function you are using is designed specifically for adding a legend easily.
If you want to keep the same color scheme as the fields image.plot function:
image(<your data>, ..., col = tim.colors())
Using this creates the exact same image without a legend.
The image and image.plot functions actually have quite different plotting functionality.
One problem (at least for me, trying to plot regional climate model data) with using the built-in image is that it cannot handle irregular grids. The image.plot function uses the poly.image function internally to create the plot. Both are included in the fields package. The good thing is that the poly.image function also can be used on its own, for example like this:
library("fields")
# create an example of an irregular 3x3 grid by adding random perturbations up to ±0.6
x <- matrix(rep(1:3,each=3) + 0.6*runif(9), ncol=3)
y <- matrix(rep(7:9,times=3) + 0.6*runif(9), ncol=3)
# 9 values, from 1 to 9
z <- matrix(1:9,nrow=3)
# Please avoid the default rainbow colours, see e.g.
# https://www.climate-lab-book.ac.uk/2014/end-of-the-rainbow/
# Other examples of colour schemes: https://colorbrewer2.org/
col <- colorRampPalette(c("#2c7bb6","#abd9e9","#ffffbf","#fdae61","#d7191c"))(9)
par(mfrow=c(1,3), mar=c(4,4,4,1), oma=c(0,0,0,0))
image(x=7:9,y=1:3,z,col=col, main="image()\n Only regular grid. Also note transposition.")
image.plot(x,y,z,col=col, main="image.plot()\n Always with colorbar.")
poly.image(x,y,z,col=col, main="poly.image()\n Does not include colorbar.")
[a] [b] [c]
Chrome Chrome Chrome
Chrome Internet Explorer Chrome
Chrome Chrome Chrome
Firefox Firefox Chrome
Internet Explorer Chrome Chrome
Safari Safari Chrome
Im new to SPSS so sorry if this is basic. Trying to product a graphical representation (line-graph) of the change in frequency for each option from a to b. And then a,b,c.
I figure, for each variable I need to calculate the % for each option and then plot that.
Any help would be greatly appreciated.
The short answer to generate what I believe you want is to reshape your data from wide to long, and then produce the summary chart. Example below:
*Making fake data that looks like yours.
input program.
loop #i = 1 to 1000.
compute caseid = #i.
compute A = TRUNC(RV.UNIFORM(1,4)).
compute B = TRUNC(RV.UNIFORM(1,4)).
compute C = TRUNC(RV.UNIFORM(1,4)).
end case.
end loop.
end file.
end input program.
dataset name Sim.
value labels A B C
1 'Chrome'
2 'Firefox'
3 'IE'.
*Reshape Wide to long.
VARSTOCASES
/MAKE Browser from A B C
/INDEX Period.
*Now make the summary chart.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=Period COUNT()[name="COUNT"] Browser
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: Period=col(source(s), name("Period"), unit.category())
DATA: COUNT=col(source(s), name("COUNT"))
DATA: Browser=col(source(s), name("Browser"), unit.category())
GUIDE: axis(dim(1), label("Period"))
GUIDE: axis(dim(2), label("Count"))
GUIDE: legend(aesthetic(aesthetic.color.interior), label("Browser"))
SCALE: cat(dim(1))
SCALE: linear(dim(2))
SCALE: cat(aesthetic(aesthetic.color.interior), include("1.00", "2.00","3.00"))
ELEMENT: line(position(Period*COUNT), color.interior(Browser), missing.wings())
END GPL.
Which produces this chart:
If you have repeated measures data (i.e. the same persons browser over multiple time periods) you have more structure in the data that can be charted. One way You may consider area charts conditioned on the initial state. Below is an example, which with some post-hoc editing the chart produces this:
do if Period = 1.
compute initial_browser = Browser.
else if Period > 1.
compute initial_browser = lag(Browser).
end if.
value labels initial_browser
1 'Chrome'
2 'Firefox'
3 'IE'.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=Period COUNT()[name=
"COUNT"] initial_browser Browser
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: Period=col(source(s), name("Period"), unit.category())
DATA: COUNT=col(source(s), name("COUNT"))
DATA: initial_browser=col(source(s), name("initial_browser"),unit.category())
DATA: Browser=col(source(s), name("Browser"), unit.category())
GUIDE: axis(dim(1), label("Period"))
GUIDE: axis(dim(2), label("Count"))
GUIDE: axis(dim(4), label("Initial Browser"), opposite())
GUIDE: legend(aesthetic(aesthetic.color.interior), label("Browser"))
SCALE: cat(dim(1))
SCALE: linear(dim(2), include(0))
SCALE: cat(dim(4))
SCALE: cat(aesthetic(aesthetic.color.interior), include("1.00", "2.00",
"3.00"))
ELEMENT: area.stack(position(Period*COUNT*1*initial_browser),
color.interior(Browser), missing.wings())
END GPL.
There are alot of other charting possibilities if this is the case.
I'd like to create a printable output file from within Squeak, for instance to create a report.
I've done a little Googling and I'm surprised by how little material in the way of examples relating to creating printable files exist. However, I've found a couple of classes class called PostscriptCanvas and EPSCanvas and a method within it called morphAsPostscript.
To try these classes out I created a tiny code example and my first workspace example was:
p := PasteUpMorph new.
p extent: 300#300.
p position: 20#20.
p borderColor: Color black.
p setProperty: #cornerStyle toValue: #rounded.
p openInWorld.
(FileStream newFileNamed: 'test1.ps') nextPutAll: (PostscriptCanvas morphAsPostscript: p)
unfortunately the above doesn't work and halts with doesnotUnderstand #pageBBox.
when I try the example again but this time using the EPSCanvas class:
p := PasteUpMorph new.
p extent: 300#300.
p position: 20#20.
p borderColor: Color black.
p setProperty: #cornerStyle toValue: #rounded.
p openInWorld.
(FileStream newFileNamed: 'test2.eps') nextPutAll: (EPSCanvas morphAsPostscript: p).
this time I generate output but the corners of the box aren't rounded in the eps file (they are rounded on the screen).
So, my questions are:
Am I on the right track as far as generating printable output or should I be using an alternative technique?
Why does the first example crash with doesnotUnderstand #pageBBox?
Why does the second example almost work but does not render the rounded corners?
Thanks
Kevin
It's not just Squeak - producing printable output is fearsomely difficult in any programming language. Whenever I've done project planning and people mention reports, I immediatel double (at least) the project estimates. Personally, I would recommend writing the data to a file in some well-known format such as XML or CSV and then use a report-writing package to produce the actual reports.
Sorry not to be more helpful!