I mean the 0 2 4 6 labels going up the side of the axis of a Stata scatter graph.
Is there any way to do this without creating a whole new variable as I've seen other people do?? This really shouldn't be so complicated.
You can clone Stata and write Rosieata if you can think up simpler code!
More seriously, I don't know how a new variable would help here at all, but you give no code to discuss.
Here is some technique:
sysuse auto, clear
set scheme s1color
scatter rep78 price, ms(Oh) yla(1 2 3 4 5, ang(h))
scatter rep78 price, ms(Oh) yla(1 "{bf:1}" 2 "{bf:2}" 3 "{bf:3}" 4 "{bf:4}" 5 "{bf:5}", ang(h))
ssc inst mylabels
mylabels 1/5, prefix("{bf:") suffix("}") local(yla)
scatter rep78 price, ms(Oh) yla(`yla', ang(h))
Related
I am trying to include the count labels on stacked bar plots which represent percentages. I want to show x-amount of individuals make up the graphed percentages. However, when I include the count labels my y-axis gets blown out of proportion because it changes to match the count data, not the percentages. Also, the bars are removed from the graph too? I have reviewed other posts similar to this, such as: "How to add percentage or count labels above percentage bar plot?". I cannot find the error in my r command.
My command used is as follows:
sumplot<-ggplot(tagSummary,aes(x=recvDeployName,y=nDet,fill=speciesSci))+
geom_bar(position="fill",stat="identity")+
geom_text(aes(label=nDet),position=position_stack(vjust=0.5))+
theme(axis.text.x=element_text(angle=90,hjust=1))+
scale_y_continous(labels=scales::percent_format())
Example of data being graphed:
speciesSci recvDeployName nDet
1 Arenaria interpres Bucktoe Preserve 96
2 Arenaria interpres CHDE 132
3 Arenaria interpres Fortescue 22133
4 Arenaria interpres Mispillion 2031
5 Arenaria interpres Norbury 3709
6 Arenaria interpres Penn - DRL 49
What my graph looks like when I use the command example provided above:
11/17/19 Update: The r commands below seems promising:
sumplot<-ggplot(tagSummary,aes(x=recvDeployName,y=nDet,fill=speciesSci))+
geom_text(aes(label=nDet),position="fill", stat="identity")+
theme(axis.text.x=element_text(angle=90,hjust=1))+
scale_y_continuous(labels=scales::percent_format())
I just need to get the colored bars back onto the graph, representing the percentages.
Any help would be greatly appreciated. Thank you.
This gave me the result I wanted:
sumplot<-ggplot(tagSummary,aes(x=recvDeployName,y=nDet,fill=factor(speciesSci))+geom_bar(positon="fill", stat="identity")+geom_text(aes(label=nDet),position = position_fill(vjust=0.5))+theme(axis.text.x=element_text(angle=90,hjust=1))+scale_y_continuous(labels=scales::percent_format()))
Correct Graph
I am asking this question which sounds exactly like this post because it did not solve the problem. Here is my question. I have 2 plots that I want to put together with their scale perfectly in line. Here is what I got to :
As you can see the x axis is not exactly in line. Here is the code I used
bp_horiz<-ggplot(df,aes(y=Corg_rate))+
geom_boxplot()+
theme_classic()+
labs(y="Corg annual rate")+
coord_flip()
histo<-ggplot(data=df, aes(Corg_rate))+
geom_histogram(fill="grey",col="black")+
labs(x="Corg annual rate",y="Counts")+
theme_classic()+
labs(x=NULL,y="Counts")
plot_grid(histo,boxplot_horiz,ncol=1,align="v",rel_heights=c(4,1),axis = 'lr')
I tried to change the align parameters from v to h to hv without success.
I tried using egg with the same problem on non alignment. I tried using ggMarginal but it does not work when the center plot is a histogram.
How would you solve this issue?
I do't know how to add data but to make things clearer here is the beginning of it:
Corg_rate
1 -0.0147
2 0.0106
3 0.114
4 -0.00230
5 0.0105
6 -0.0574
7 0.0102
8 -0.00472
9 0.0335
10 -0.00803
I finally found a way: writing the scale for each plot. I have therefore added to the code
for the boxplot (before coord_flip)
+scale_y_continuous(limits=c(min(df$Corg_rate),max(df$Corg_rate)))
and for the histogram
+scale_x_continuous(limits=c(min(df$Corg_rate),max(df$Corg_rate)))
The function plot_grid then works just fine and the two plots have their scales aligned
I have following problem that I have to place the bars at dedicated x-values.
I have a series, say of a frequency (say from 0 to 100) where i want to show the values for dedicated frequencies.
For example:
width : 1 1 3 2 4
height: 6 2 1 5 4
x-frequency for example: 1,2,3 6,12 is where to plot the bars
when i do the barplot:
barplot(width, height)
axis(1,,seq(0,15,1))
i get the following:
But that is not what i want, i want the bars at locations according to my values 1,2,3 6,12
I´ve found a solution: since barplot does the positioning, i would have to do it another way, i can place a bar with the "rect" command:
rect(xleft=3, ybottom=0, xright=5, ytop=6)
This is exactly what i wanted.
I have a data
equip ballots freq %Undercounts
1 LEVER 427780 17016 3.98
2 OPTICAL 1436159 39090 2.72
3 PAPER 3454 113 3.27
4 PUNCH 823921 38462 4.67
I want to plot equipment on the X-axis. And ballots should be at 100% for each equip. Freq should be the percentage of the bars and be represented as a percentage of ballots.
I have tried barplot and lattice plots. But I'm getting some error which seems like my data is not in form. Can someone please help me in what I might be missing.
Thanks.
It is very simple to accomplish with lattice
barchart(freq/ballots + (ballots-freq)/ballots ~ equip, tab, stack=TRUE)
Base graphics require more code and some obscure parameter tweaking to look good
attach(tab)
barplot(rbind(freq/ballots, 1), width=.8, space=.25)
mtext(equip, side=1, at=1:nrow(tab)-.4)
I've got a matrix that I've plotted using the bar plot function to create a stacked bar plot of changes in percent of something (alphabets) over time. The matrix looks like:
Year V W X Y Z
1 7.5397 20.6349 11.1111 0.3968 60.3175
2 8.3333 21.4286 11.9048 0.3968 57.9365
3 23.8095 9.5238 9.5238 0.3968 56.7460
4 23.4127 10.7143 10.3175 1.1905 54.3651
5 23.4127 11.1111 10.7143 1.9841 52.7778
6 30.0000 2.4000 19.2000 2.4000 46.0000
All these should be the same height, because they add to 100, but in my plot, all the heights are just a bit different at the top. My bar plot code looks like this:
>barplot(t(as.matrix(mydata[,2:6])),names.arg=unique(mydata$Year),axis.lty=1, ylim=c(0,100),
xlab="Year", ylab="Percent of Categories", etc.
I've tried adjusting the ylim, changing xpd to =FALSE, and making some axis argument adjustments, and I'm not sure what else to try before scratching the whole thing and retrying with a different plotting function. Any help is appreciated.