Hello,
R 2.3.0
Windows XP
I have spent quite a bit of time trying to resolve my problem below, which
included a R site search.
The "vertical bars" syntax below produces a vertical bar chart with
the values displayed above each bar. I want to cast this graphic horizontally,
but I have not been able to arrive at a suitable outcome. The best I have been
able to do, using the second block of syntax below, is to get the values to
display along the right edge of the horizontal graph whereas my goal is to have
them displayed just off the ends of each horizontal bar, as they are on the
veritical graph.
I was hoping someone could provide me with direction or a solution to this
problem.
#Vertical bars syntax:
math.bar <- c(53,31,55,28,55,100)
names(math.bar) <- c('Grade \n 3','Grade \n 4','Grade \n
5','Grade \n 6','Grade \n 7','Grade \n 8')
o <- rev(order(math.bar))
math.bar <- math.bar[o]
par(ps=10)
math.barplot <- barplot(math.bar, main = list("Death Rates in
Virginia", font = 1), col=c('darkblue'), names=c('Grade \n
3','Grade \n 4','Grade \n 5','Grade \n 6','Grade
\n 7','Grade \n 8'), ylim=c(0,100), ylab="Percentage",
xlab="Grade Level")
text(math.barplot, math.bar+5, math.bar, xpd = TRUE)
#Horizontal bars syntax:
par(mar=c(5, 9, 5, 2))
math.bar <- c(53,31,55,28,55,100)
names(math.bar) <- c('Grade 3','Grade 4','Grade
5','Grade 6','Grade 7','Grade 8')
o <- rev(order(math.bar))
math.bar <- math.bar[o]
par(ps=10)
math.barplot <- barplot(math.bar, horiz=T, las=2, main = list("Death
Rates in Virginia", font=1), col=c('darkblue'), xlim=c(0,100),
ylab="Grade Level", xlab="Percent")
mtext(side=4, at=math.barplot, math.bar, las=2)
Thank you,
Greg Blevins
The Market Solutions Group
[[alternative HTML version deleted]]
Dave Armstrong
2006-May-15 12:23 UTC
[R] Trying to get values to display on horizontal barchart
Dear Greg,
How about something like this
par(mar=c(5, 9, 5, 2))
math.bar <- c(53,31,55,28,55,100)
names(math.bar) <- c('Grade 3','Grade 4','Grade
5','Grade 6','Grade
7','Grade 8')
o <- rev(order(math.bar))
math.bar <- math.bar[o]
par(ps=10)
math.barplot <- barplot(math.bar, horiz=T, las=2, main = list("Death
Rates
in Virginia", font=1), col=c('darkblue'), xlim=c(0,110),
ylab="",
xlab="Percent")
mtext("Grade Level", side=2, line=5, at=mean(math.barplot), )
text(math.bar, math.barplot, math.bar, pos=4)
HTH,
Dave.
On 5/15/06, gblevins <gblevins@mn.rr.com> wrote:>
> Hello,
> R 2.3.0
> Windows XP
>
> I have spent quite a bit of time trying to resolve my problem below, which
> included a R site search.
>
> The "vertical bars" syntax below produces a vertical bar chart
with the
> values displayed above each bar. I want to cast this graphic horizontally,
> but I have not been able to arrive at a suitable outcome. The best I have
> been able to do, using the second block of syntax below, is to get the
> values to display along the right edge of the horizontal graph whereas my
> goal is to have them displayed just off the ends of each horizontal bar, as
> they are on the veritical graph.
>
> I was hoping someone could provide me with direction or a solution to this
> problem.
>
> #Vertical bars syntax:
> math.bar <- c(53,31,55,28,55,100)
> names(math.bar) <- c('Grade \n 3','Grade \n
4','Grade \n 5','Grade \n
> 6','Grade \n 7','Grade \n 8')
> o <- rev(order(math.bar))
> math.bar <- math.bar[o]
> par(ps=10)
> math.barplot <- barplot(math.bar, main = list("Death Rates in
Virginia",
> font = 1), col=c('darkblue'), names=c('Grade \n
3','Grade \n 4','Grade \n
> 5','Grade \n 6','Grade \n 7','Grade \n 8'),
ylim=c(0,100),
> ylab="Percentage", xlab="Grade Level")
> text(math.barplot, math.bar+5, math.bar, xpd = TRUE)
>
> #Horizontal bars syntax:
> par(mar=c(5, 9, 5, 2))
> math.bar <- c(53,31,55,28,55,100)
> names(math.bar) <- c('Grade 3','Grade 4','Grade
5','Grade 6','Grade
> 7','Grade 8')
> o <- rev(order(math.bar))
> math.bar <- math.bar[o]
> par(ps=10)
> math.barplot <- barplot(math.bar, horiz=T, las=2, main =
list("Death Rates
> in Virginia", font=1), col=c('darkblue'), xlim=c(0,100),
ylab="Grade Level",
> xlab="Percent")
> mtext(side=4, at=math.barplot, math.bar, las=2)
> Thank you,
>
> Greg Blevins
> The Market Solutions Group
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
--
Dave Armstrong
University of Maryland
Dept of Government and Politics
3140 Tydings Hall
College Park, MD 20742
Office: 2103L Cole Field House
Phone: 301-405-9735
e-mail: darmstrong@gvpt.umd.edu
web: www.davearmstrong-ps.com
Facts are meaningless. You can use facts to prove anything that's even
remotely true. - Homer Simpson
To this day, philosophers suffer from Plato's disease: the assumption that
reality fundamentally consists of
abstract essences best described by words or geometry. (In truth, reality is
largely a probabilistic affair best
described by statistics) - Steve Sailer "The Unexpected Uselessness of
Philosophy"
[[alternative HTML version deleted]]