So I have a dotplot with 4 panels, each panel has 6 horizontal bars. I'm trying to make it so that when a bar is past a certain X value (denoted by reference line), it will be a different color. I cant find anything that will make R do this automatically, soI figured there must be a way to manually tell it to make a specific row of a specific panel a certain color?
Heres my code:
dotplot(somematrix,groups=FALSE,
layout=c(2,2),aspect=1,
origin=0,type=c("p","h"),
main="Main label",
xlab="X label",
scales=list(x=list(tck=0, alternating=TRUE)),
panel=function(...){
panel.fill(rgb(.9,.9,.9))
panel.grid(h=0,v=-1,col="white",lwd=2)
panel.abline(v=20,col="red",lwd=3)
panel.barchart(col=c("blue","blue","blue","blue","red","blue"),cex=1.1,...)
}
)
Related
I have a large dataset and I am trying to create a stacked bar chart that contains countries and years. Here is what I have right now:
counts <- table(IMDB$country, IMDB$year)
barplot(counts, main="Movies produced in each country by year",
xlab="Years", col=colorRampPalette(brewer.pal(name="Dark2", n = 8))(15),
legend = rownames(counts))
How can I make all the countries visible in the legend because in my case not all of them appear, moreover, the colours look too similar so I can't distinguish sometimes between them?
You need to set a custom length and width parameter before starting your plot. See
?png() or the related pdf(), svg(), etc.
Your best palette choices are those with a sufficient spread across the color wheel to allow easy discrimination.
Added: Re. your example request, there are many already here and in the examples using "?". However...
png(filename= "rplotpng.png",width=1000, height=400, units ="px")
plot(1:30,rep(2,30))
dev.off()
# you will find the output in your working directory.
I would like to add some totals on the right side of the plot (above and under the legend). And also under the title of the x axis.
I found how to add text within the plot, or add multiple legends of something ploted, but I don't want to do either one. I just want to calculate some totals and display them as mentioned above. Is it in any way possible?
As it is now:
As I would like it to be:
Hi I need to show the String titles below the bars of my Bar Chart created from Core Plot. I have many places in Core Plot framework but didn't find how to put text below the bars?
I need to show titles just like shown in the attached image.
Please suggest!
There are a couple of ways to make axis labels that are not numeric representations of the data value.
If you are plotting categorical data, you can set the scale type of the plot space to show categorical labels and return the text of the label from the datasource for the plot value (e.g., the bar location for a bar plot).
From the "Vertical Bar Chart" demo in the Plot Gallery example app:
// setup
[barPlotSpace setScaleType:CPTScaleTypeCategory forCoordinate:CPTCoordinateX];
If you're not plotting categorical data or you just need more control over the labels, you can create custom axis labels. Set the axis labelingPolicy to CPTAxisLabelingPolicyNone, create a set of axis labels, and assign it to the axisLabels property. There are several demos in the example apps including the "Composite Plot" demo in the Plot Gallery example app. With CPTAxisLabelingPolicyNone, the tick marks and labels are independent, so if you want tick marks, you also need to set the majorTickLocations and/or minorTickLocations.
I've been working on putting together a broken y-axis histogram, in order to display one very tall bar while not having the other bars invisible. In particular, I would like to be able to control not only what the tics are on the x-axis (they need to show the count bins from the histogram, not just the axes), but also how many tics there are on the x-axis.
This question got me started, though I had to figure out on my own how to use the xtics option in plotrix's gap.barplot to show the histogram bins:
Put a break in the Y-Axis of a histogram
However, I still cannot figure out a way to plot a broken y-axis histogram without having it try to plot a tic for every single bin. Does anybody know a way to do this?
I'm trying to create a dot chart in Stata, splitting it into two categories
Running a chunk of code:
sysuse nlsw88, clear
drop if race == 3
graph dot (mean) wage, over(occ) by(race)
Creates such output:
So far so good but I'd like to remove labels of Y axis from the right graph to give the data some more space.
The only way I've been able to do that was to manually edit graph and hide the axis label object:
Is there a way to do it programmatically? I do know I could use one more over() but in some graphs of mine that is already taken.
I believe the solution is buried in help bystyle and help by_option. However, I can't get it to work with your example (I'm on Stata 12). But the description is clear. For example:
A bystyle determines the overall look of the combined graphs,
including
whether the individual graphs have their own axes and labels or if instead the axes and labels are shared across graphs arrayed in the
same row and/or in the same column;
...
There are options that let you control each of the above attributes --
see [G-3] by_option --
And also
iyaxes and ixaxes (and noiyaxes and noixaxes) specify whether the y axes and x axes are
to be displayed with each graph. The default
with most styles and
schemes is to place y axes on the leftmost graph of each row and to place x axes on
the bottommost graph of each column. The y and
x axes include the
default ticks and labels but exclude the axes titles.
If for some reason that doesn't work out, something like
sysuse nlsw88, clear
drop if race == 3
graph dot (mean) wage, over(occ) by(race)
gr_edit .plotregion1.grpaxis[2].draw_view.setstyle, style(no)
does (but I don't really like the approach). You can mess with at least the axis number [#] to do a bit of customization. I guess recording changes in the graphical editor and then recycling the corresponding code, may be one way out of difficult situations.