--- title: Plotting the brightest 200 stars format: html: copy-code: true embed-resources: true fig-responsive: true fig-width: 8 --- Here we try to replicate what we did in class but with R. ```{r} #library(tidyverse) or you really just need to two below library(magrittr) library(ggplot2) ``` We begin by reading in the data, ```{r} data <- read.csv('./brightest_200.csv', header=FALSE) head(data) ``` and then attach meaningful column names: ```{r} names(data) <- c("formal name", "common name", "RA", "DEC") head(data) ``` Now we have the same issue we had in class, where the Right Ascension values are not in a format we can easily plot. As such, we need to convert them to decimal form. ```{r} ra2decimal <- function(s) { hrs <- as.numeric(substr(s, 1, 2)) mins <- as.numeric(substr(s, 4, 5)) return (15 * (hrs + mins / 60)) } data$RA %>% ra2decimal ``` Those look pretty good, so I'll go ahead and add another table column with those converted values. ```{r} data$RA_decimal <- data$RA %>% ra2decimal head(data) ``` Now we can plot! If we just did a straight Cartesian plane: ```{r} ggplot(data=data, aes(x=RA_decimal, y=DEC)) + geom_point() ``` Or if we want to try to replicate the "aitoff" projection we used in Python: ```{r} ggplot(data=data, aes(x=RA_decimal, y=DEC)) + geom_point() + coord_map("aitoff") ``` which looks great, outside the the gridlines being a bit silly. But that could be tweaked.