How to include variables with spaces?

45 views
Skip to first unread message

Stuart Luppescu

unread,
Feb 6, 2012, 4:36:30 PM2/6/12
to ggplot2
Hello, I'm having trouble using variables with spaces in the names.
Here's the data set:
Summative.Rating Match.Rate
1 Unsatis 16.66667
3 Basic 14.70588
5 Profic 41.22807
7 Disting 19.56522

I can plot this like this:
qplot(data=test, x=Summative.Rating, y=Match.Rate, geom="bar")

but the label on the x-axis turns out as "Summative.Rating". If I change
the name of the column to "Summative Rating" and make the qplot call:
qplot(data=test, x="Summative Rating", y="Match.Rate", geom="bar")

it just gives me one bar of hight "Match.Rate", labeled "Summative
Rating".

When I use this:
ggplot(data=test, aes(x="Summative Rating", y=Match.Rate))+geom_bar(stat="identity")

I get one bar of height 92.xx, which is the sum of the Match.Rates.

I know I can change the axis labels using xlab() and ylab() but I don't
understand why I only get one bar. Can someone explain this to me?
--
Stuart Luppescu -=- slu .at. ccsr.uchicago.edu
University of Chicago -=- CCSR
才文と智奈美の父 -=- Kernel 3.2.1-gentoo-r2
Michael Dewey: When I started I found the free
documents useful but I made most progress when I
bought MASS. I do realise that liking books is a
bit last millennium. Thomas Lumley: Very late last
millenium, though. "When I were young[er] we
didn't have all these fancy yellow books." --
Michael Dewey and Thomas Lumley (about different
kinds of documentation for R) R-help
(January 2006)

Dennis Murphy

unread,
Feb 6, 2012, 5:07:15 PM2/6/12
to Stuart Luppescu, ggplot2
Hi:

This works for me in 0.9.0:

DF <- read.table(textConnection("
Unsatis 16.66667
Basic 14.70588
Profic 41.22807
Disting 19.56522"), header = FALSE)
names(DF) <- c('Summative Rating', 'Match Rate')

# Note the backticks:
ggplot(DF, aes(x = `Summative Rating`, y = `Match Rate`)) +
geom_bar()

Why you would want to use a bar chart to display numeric summaries is
another issue.

Dennis

Stuart Luppescu

unread,
Feb 6, 2012, 5:12:25 PM2/6/12
to Dennis Murphy, ggplot2
On Mon, 2012-02-06 at 14:07 -0800, Dennis Murphy wrote:
> Hi:
>
> This works for me in 0.9.0:
>
> DF <- read.table(textConnection("
> Unsatis 16.66667
> Basic 14.70588
> Profic 41.22807
> Disting 19.56522"), header = FALSE)
> names(DF) <- c('Summative Rating', 'Match Rate')
>
> # Note the backticks:
> ggplot(DF, aes(x = `Summative Rating`, y = `Match Rate`)) +
> geom_bar()

Aha. Backticks! Thanks, Dennis.

> Why you would want to use a bar chart to display numeric summaries is
> another issue.

Better than a pie chart. ;-) Actually, this is just a simplified piece
of the whole display.


--
Stuart Luppescu -=- slu .at. ccsr.uchicago.edu
University of Chicago -=- CCSR
才文と智奈美の父 -=- Kernel 3.2.1-gentoo-r2

Knut Krueger: Is there any function available to
combine those p values? Stephan Kolassa: ?"+"
-- Knut Krueger and Stephan Kolassa (about ways to
combine p values from different tests)
R-help (July 2010)




Reply all
Reply to author
Forward
0 new messages