# Week 4 Data Visualization Lab

# Install the package ggplot2

```{r}
options(repos = c(CRAN = "https://cloud.r-project.org"))
install.packages("ggplot2")

```

# Anytime I want to use this package I need to load it

```{r}
library(ggplot2)
```

```{r}
View(cars)

```

# A quick base R plot - this is not ggplot2

```{r}
plot(cars)

```

# Our first ggplot

# we need data + aes + geoms

```{r}
ggplot(data = cars) +
  aes(x=speed, y=dist) +
geom_point()
 
```

```{r}
p <- ggplot(data = cars) +
  aes(x=speed, y=dist) +
  geom_point()
```

# Add a line geom with geom_line()

```{r}
p + geom_line()

```

# Add a trend line close to the data

```{r}
p + geom_smooth()

```

```{r}
p + geom_smooth(method = "lm")

```

#---------#

# Read in our durg expression data

```{r}
url <- "https://bioboot.github.io/bimm143_S20/class-material/up_down_expression.txt"
genes <- read.delim(url)
head(genes)
```

# Lets make a first plot attempt

```{r}
g<- ggplot(data = genes) +
  aes(x=Condition1, y=Condition2, col=State) +
  geom_point()
g
```

# Add some color

```{r}
g + scale_color_manual(values = c("blue", "grey", "red")) +
  labs(title = "Gene Expression Changes",
       x="Control (No Drug)", y="Drug Treatment") +
  theme_bw()

```

# Q. How many genes are in this data set

```{r}
nrow(genes)

```

# Q. How many columns

```{r}
ncol(genes)
```

#Q How many upregulated genes

```{r}
table(genes$State)

```

# Q. What fraction of total genes are up regulated?

```{r}
round( (table(genes$State)/nrow(genes)) *100, 2)
```

\`
