Adding sample size to box plot - size

We measured antibody levels in different age groups, and our sample size for each group was different.
I would like to add the sample size of the respective group at the top of my box plot (i.e. sample size in toddler boys). The photo attached shows one of my bar graphs.
my code to create the bar graph:
graph box igg1ugml_log10, over(female_sex) over(age_groups) ///
bar(samplesize) graphregion(color(white)) ///
title(Anti-EPEC IgG1 (ug/ml) in boys and girls) asyvars ///
ylabel(2.69897 "500" 3 "1,000" 3.3 "2000" 3.69 "5000" 3.95 "9000")
bar graph example

For adding text to graph box, use the documented text() option. Here is a reproducible example. Other than using the Graph Editor, I don't have any recipe for working out text position other than fiddling towards what looks good enough.
sysuse auto, clear
gen logprice = log10(price)
ssc install mylabels
su price
mylabels 3000(2000)15000, myscale(log10(#)) local(yla)
graph box logprice, over(foreign) yla(`yla', ang(h)) ///
text(4.25 21.2 "{it:n} = 52") text(4.25 79.8 "{it:n} = 22") ///
ysc(r(. 4.3)) scheme(s1color) ytitle(Price (USD))
Note. To show the mu of microgram properly, see help graph text in Stata and search for Greek letters.
EDIT
stripplot from SSC can produce box plots too, although both its defaults and its possibilities differ from graph box. Here is a reproducible example.
sysuse auto, clear
egen count = count(mpg), by(rep78)
gen where = 10.5
stripplot mpg , box vertical ms(none) pctile(5) over(rep78) ///
yla(12 41 15(5)40, ang(h)) ///
addplot(scatter where rep78, mla(count) ms(none) mlabpos(0) ///
mlabsize(medsmall)) scheme(s1color)
Again, although this is reproducible code, the choice of 10.5 results from play with other values not shown here. You could try to automate a choice with a calculation based on the sample maximum and minimum and, naturally, your preference for where it should be. If you were producing dozens of these, that would be a good idea. For a single plot for a paper or presentation, I would just play.

Related

Altair sorting Chart

I'm trying to plot the data of my DataFarme in a groupedChart and I want the columns to preserve the order I gave them before. The data looks as follows (its not all there but its in the same way organized)
dataframe
When I plot it I get the following Graph:
graph
So the months were sorted even though I specified not to sort in the chart. I used the following code:
chart2 = alt.Chart(melted).mark_bar().encode(
column=alt.Column('variable',sort=None),
x=alt.X('room',sort=None),
y=alt.Y('value'),
color='room',
tooltip= ['room', 'value']
)
Does anyone know how I could fix that?
You've already used sort=None, which is the correct way to make scales in a non-faceted chart reflect the input order.
The missing piece is that faceted charts share scales by default (See Scale and Guide Resolution), so each facet is being forced to share an order.
If you make the x scale resolution independent, then each facet should retain the input order:
chart2 = alt.Chart(melted).mark_bar().encode(
column=alt.Column('variable',sort=None),
x=alt.X('room',sort=None),
y=alt.Y('value'),
color='room',
tooltip= ['room', 'value']
).resolve_scale(x='independent')

How to calculate the Horizontal and Vertical FOV for the KITTI cameras from the camera intrinsic matrix?

I would like to calculate the Horizontal and Vertical field of view from the camera intrinsic matrix for the cameras used in the KITTI dataset. The reason I need the Field of view is to convert a depth map into 3D point clouds.
Though this question has been asked quite a long time ago, I felt it needed an answer as I ran into the same issue and was unable to find any info on it.
I have however solved it using the information available in this document and some more general camera calibration documents
Firstly, we need to convert the supplied disparity into distance. This can be done through fist converting the disp map into floats through the method in the dev_kit where they state:
disp(u,v) = ((float)I(u,v))/256.0;
This disparity can then be converted into a distance through the default stereo vision equation:
Depth = Baseline * focal length/ Disparity
Now come some tricky parts. I searched high and low for the focal length and was unable to find it in documentation.
I realised just now when writing that the baseline is documented in the aforementioned source however from section IV.B we can see that it can be found in P(i)rect indirectly.
The P_rects can be found in the calibration files and will be used for both calculating the baseline and the translation from uv in the image to xyz in the real world.
The steps are as follows:
For pixel in depthmap:
xyz_normalised = P_rect \ [u,v,1]
where u and v are the x and y coordinates of the pixel respectively
which will give you a xyz_normalised of shape [x,y,z,0] with z = 1
You can then multiply it with the depth that is given at that pixel to result in a xyz coordinate.
For completeness, as P_rect is the depth map here, you need to use P_3 from the cam_cam calibration txt files to get the baseline (as it contains the baseline between the colour cameras) and the P_2 belongs to the left camera which is used as a reference for occ_0 files.

How to refine the Graphcut cmex code based on a specific energy functions?

I download the following graph-cut code:
https://github.com/shaibagon/GCMex
I compiled the mex files, and ran it for pre-defined image in the code (which is rgb image)
I wanna optimize the image segmentation results,
I have probability map of the image, which its dimension is (width,height, 5). Five probability distribution over the image dimension are stacked together. each relates to one the classes.
My problem is which parts of code should according to the probability image.
I want to define Data and Smoothing terms based on my application.
My question is:
1) Has someone refined the code according to the defining different energy function (I wanna change Unary and pair-wise formulation).
2) I have a stack of 3D images. I wanna define 6-neighborhood system, 4 neighbors in current slice and the other two from two adjacent slices. In which function and part of code can I do the refinements?
Thanks

Constructing a bubble trellis plot with lattice in R

First off, this is a homework question. The problem is ex. 2.6 from pg.26 of An Introduction to Applied Multivariate Analysis. It's laid out as:
Construct a bubble plot of the earthquake data using latitude and longitude as the scatterplot and depth as the circles, with greater depths giving smaller circles. In addition, divide the magnitudes into three equal ranges and label the points in your bubble plot with a different symbol depending on the magnitude group into which the point falls.
I have figured out that symbols, which is in base graphics does not work well with lattice. Also, I haven't figured out if lattice has the functionality to change symbol size (i.e. bubble size). I bought the lattice book in a fit of desperation last night, and as I see in some of the examples, it is possible to symbol color and shape for each "cut" or panel. I am then working under the assumption that symbol size could then also be manipulated, but I haven't been able to figure out how.
My code looks like:
plot(xyplot(lat ~ long | cut(mag, 3), data=quakes,
layout=c(3,1), xlab="Longitude", ylab="Latitude",
panel = function(x,y){
grid.circle(x,y,r=sqrt(quakes$depth),draw=TRUE)
}
))
Where I attempt to use the grid package to draw the circles, but when this executes, I just get a blank plot. Could anyone please point me in the right direction? I would be very grateful!
Here is the some code for creating the plot that you need without using the lattice package. I obviously had to generate my own fake data so you can disregard all of that stuff and go straight to the plotting commands if you want.
####################################################################
#Pseudo Data
n = 20
latitude = sample(1:100,n)
longitude = sample(1:100,n)
depth = runif(n,0,.5)
magnitude = sample(1:100,n)
groups = rep(NA,n)
for(i in 1:n){
if(magnitude[i] <= 33){
groups[i] = 1
}else if (magnitude[i] > 33 & magnitude[i] <=66){
groups[i] = 2
}else{
groups[i] = 3
}
}
####################################################################
#The actual code for generating the plot
plot(latitude[groups==1],longitude[groups==1],col="blue",pch=19,ylim=c(0,100),xlim=c(0,100),
xlab="Latitude",ylab="Longitude")
points(latitude[groups==2],longitude[groups==2],col="red",pch=15)
points(latitude[groups==3],longitude[groups==3],col="green",pch=17)
points(latitude[groups==1],longitude[groups==1],col="blue",cex=1/depth[groups==1])
points(latitude[groups==2],longitude[groups==2],col="red",cex=1/depth[groups==2])
points(latitude[groups==3],longitude[groups==3],col="green",cex=1/depth[groups==3])
You just need to add default.units = "native" to grid.circle()
plot(xyplot(lat ~ long | cut(mag, 3), data=quakes,
layout=c(3,1), xlab="Longitude", ylab="Latitude",
panel = function(x,y){
grid.circle(x,y,r=sqrt(quakes$depth),draw=TRUE, default.units = "native")
}
))
Obviously you need to tinker with some of the settings to get what you want.
I have written a package called tactile that adds a function for producing bubbleplots using lattice.
tactile::bubbleplot(depth ~ lat*long | cut(mag, 3), data=quakes,
layout=c(3,1), xlab="Longitude", ylab="Latitude")

Input parameters of CITemperatureAndTint (CIFilter)

I fail to understand the input parameters of the CIFilter named CITemperatureAndTint. The documentation says it has two input parameters which are both a 2D CIVector.
I played with this filter a lot - via actual code, via Core Image Fun House (example project from Apple - "FunHouse") and via iPhoto.
My intuition says that this filter should have two scalar input parameters: One for the temperature and one for the tint. If you look at the UI of iPhoto you see this:
Screenshot of iPhotos Temperature and Tint UI:
As expected: One slider for the temperature and one for the hue. How did apple "bind" the value of each slider to a 2D-Vector? akaru asked this question already but got no answer: What's up with CITemperatureAndTint having vector inputs?
I have opened a technical support incident at Apple and asked them the same question. Here is the answer from the Apple engineer:
CITemperatureAndTint has three input parameters: Image, Neutral and
TargetNeutral. Neutral and TargetNeutral are of 2D CIVector type, and
in both of them, note that the first dimension refers to Temperature
and the second dimension refers to Tint. What the CITemperatureAndTint
filter basically does is computing a matrix that adapts RGB values
from the source white point defined by Neutral (srcTemperature,
srcTint) to the target white point defined by TargetNeutral
(dstTemperature, dstTint), and then applying this matrix on the input
image (using the CIColorMatrix filter). If Neutral and TargetNeutral
are of the same values, then the image will not change after applying
this filter. I don't know the implementation details about iPhoto, but
I think the two slide bars give the Temperature and Tint changes (i.e.
differences between source and target Temperature and Tint values
already) that you want to add to the source image.
Now I have to get my head around this answer but it seems to be a very good response from Apple.
They should be 2D vectors containing the color temperature. The default of (6500, 0) will leave the color unchanged, as described here. You can see what values for color temperature give you which colors in this wikipedia link. I'm not sure what the 2nd element of the vector is for.