Graphics Reference
In-Depth Information
Figure 5-32. Left: a scatter plot with hjust=0; right: with a little extra added to x
NOTE
If you are using a logarithmic axis, instead of adding to
x
or
y
, you'll need to multiplythe
x
or
y
value
by a number to shift the labels a consistent amount.
If you want to label just some of the points but want the placement to be handled automatically,
you can add a new column to your data frame containing just the labels you want. Here's one
way to do that: first we'll make a copy of the data we're using, then we'll duplicate the
Name
column into
Name1
:
cdat
<-
subset(countries, Year
==
2009
&
healthexp
>
2000
)
cdat$Name1
<-
cdat$Name
Next, we'll use the
%in%
operator to find whereeach name that we want to keep is. This returns a
logical vector indicating which entries in the first vector,
cdat$Name1
, are present in the second
vector, in which we specify the names of the countries we want to show:
idx
<-
cdat$Name1
%in%
c(
"Canada"
,
"Ireland"
,
"United Kingdom"
,
"United States"
,
"New Zealand"
,
"Iceland"
,
"Japan"
,
"Luxembourg"
,
"Netherlands"
,
"Switzerland"
)
idx