[R] Superscripts and rounding

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Jul 28 15:25:28 CEST 2009



ehux wrote:
> I am new to the world of R/programming so this may be a really easy question.
> I thank you for your patience and help in advance 
> 
> I would like the characters km^2 to be displayed on the plot subtitle as km
> squared - two as a superscript. 
> 
> I would also like to have the numbers from the data set for longitude and
> latitude to be rounded to four decimal places.
> 
> Thank you.
> 
> plot (
>   decade[['date']],
>   decade[['value']],
> 
>   type = 'l',
>   col = 'lightsteelblue4',
>   ylab = 'Discharge [cms]',
>   main = sprintf('%s [%s]', stn[['metadata']][['name']],
> stn[['metadata']][['id']]),
>   km^2 <- expression
>   sub = sprintf('Seasonal station with natural streamflow - Lat: %s Lon: %s
>         Gross Area %s km^2 - Effective Area %s km^2',
> stn[['metadata']][['latitude']],
>         stn[['metadata']][['longitude']],stn[['metadata']][['grossarea']],
>         stn[['metadata']][['effectivearea']]),
>   cex.sub = 1, font.sub = 3, col.sub = "black"
>   )


Since I do not have the data I can only guess:

sub = substitute('Seasonal station with natural streamflow - Lat:' * a * 
' Lon:' * b * ' Gross Area ' * c * km^2 * ' - Effective Area ' * d * km^2',
     list(a = stn[['metadata']][['latitude']],
          b = stn[['metadata']][['longitude']],
          c = stn[['metadata']][['grossarea']],
          d = stn[['metadata']][['effectivearea']]))


Uwe Ligges




More information about the R-help mailing list