Relation among Age, Marriage & House Ownership

library(ggplot2)
library(ggthemes)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
P<-read.csv("workshop 2.csv")

ggplot(data=P, aes(marital, age)) +
   geom_boxplot(outlier.shape = NA) +
   geom_boxplot(aes(col= housing)) +
   labs(title="Relation among Age, Marriage & House ownership", 
        y="Age", 
        x="Status") +
   theme_classic()

Explanation: This box plot shows the relationship among three variables: Age, Marital status, and whether to own a house. Around half of single (aged around 30+/-) and divorced (aged around 45+/-) people have their own homes, and for married people the number of people owning a house is slightly less than 50% of all married people.

Stock Price comparison of Apple Inc.

library(ggplot2)
library(ggthemes)
library(plotly)

apple<-read.csv("AAPL.csv")

x<-ggplot(data=apple) +
   geom_point(mapping=aes(x=Open, y=Close, color=Months)) +
   geom_smooth((mapping=aes(x=Open, y=Close)), method="lm", col="firebrick", size=0.5, se=FALSE) +
   facet_wrap(~Quarter, ncol=2) +
   labs(title="Apple Inc. Stock Price", 
        y="Closing Price (USD)", 
        x="Openning Price (USD)") +
   theme_economist()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
ggplotly(x)
## `geom_smooth()` using formula = 'y ~ x'

Explanation: This scatter plot represents Apple Inc. stocks’ opening and closing price for a year divided into quarters. Quarter: 1 (Jan-March); 2 (April-June); 3 (Sept) & 4 (Oct-Dec).

Stock Price Animation

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks plotly::filter(), stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(ggthemes)
library(gganimate)

apple<-read.csv("AAPL.csv")
apple
##     Date Open Close Months Quarter
## 1      1  130   125      1       1
## 2      1  127   126      1       1
## 3      1  127   125      1       1
## 4      1  126   130      1       1
## 5      1  130   130      1       1
## 6      1  130   131      1       1
## 7      1  131   133      1       1
## 8      1  134   133      1       1
## 9      1  132   135      1       1
## 10     1  135   136      1       1
## 11     1  137   135      1       1
## 12     1  134   135      1       1
## 13     1  135   138      1       1
## 14     1  138   141      1       1
## 15     1  140   143      1       1
## 16     1  141   142      1       1
## 17     1  143   144      1       1
## 18     1  143   146      1       1
## 19     1  145   143      1       1
## 20     1  143   144      1       1
## 21     2  144   145      2       1
## 22     2  149   151      2       1
## 23     2  148   155      2       1
## 24     2  153   152      2       1
## 25     2  151   155      2       1
## 26     2  154   152      2       1
## 27     2  154   151      2       1
## 28     2  149   151      2       1
## 29     2  151   154      2       1
## 30     2  152   153      2       1
## 31     2  153   155      2       1
## 32     2  154   154      2       1
## 33     2  152   153      2       1
## 34     2  150   148      2       1
## 35     2  149   149      2       1
## 36     2  150   149      2       1
## 37     2  147   147      2       1
## 38     2  148   148      2       1
## 39     2  147   147      2       1
## 40     3  147   145      3       1
## 41     3  144   146      3       1
## 42     3  148   151      3       1
## 43     3  154   154      3       1
## 44     3  154   152      3       1
## 45     3  153   153      3       1
## 46     3  154   151      3       1
## 47     3  150   149      3       1
## 48     3  148   150      3       1
## 49     3  151   153      3       1
## 50     3  151   153      3       1
## 51     3  152   156      3       1
## 52     3  156   155      3       1
## 53     3  155   157      3       1
## 54     3  157   159      3       1
## 55     3  159   158      3       1
## 56     3  159   159      3       1
## 57     3  159   160      3       1
## 58     3  160   158      3       1
## 59     3  158   158      3       1
## 60     3  159   161      3       1
## 61     3  162   162      3       1
## 62     3  162   165      3       1
## 63     4  164   166      4       2
## 64     4  167   166      4       2
## 65     4  165   164      4       2
## 66     4  162   165      4       2
## 67     4  161   162      4       2
## 68     4  162   161      4       2
## 69     4  161   160      4       2
## 70     4  162   166      4       2
## 71     4  165   165      4       2
## 72     4  165   165      4       2
## 73     4  166   166      4       2
## 74     4  166   168      4       2
## 75     4  166   167      4       2
## 76     4  165   165      4       2
## 77     4  165   165      4       2
## 78     4  165   164      4       2
## 79     4  163   164      4       2
## 80     4  165   168      4       2
## 81     4  168   170      4       2
## 82     5  169   170      5       2
## 83     5  170   169      5       2
## 84     5  170   167      5       2
## 85     5  165   166      5       2
## 86     5  171   174      5       2
## 87     5  172   174      5       2
## 88     5  173   172      5       2
## 89     5  173   174      5       2
## 90     5  174   174      5       2
## 91     5  174   173      5       2
## 92     5  173   172      5       2
## 93     5  172   172      5       2
## 94     5  172   173      5       2
## 95     5  173   175      5       2
## 96     5  176   175      5       2
## 97     5  174   174      5       2
## 98     5  173   172      5       2
## 99     5  171   172      5       2
## 100    5  172   173      5       2
## 101    5  173   175      5       2
## 102    5  177   177      5       2
## 103    5  177   177      5       2
## 104    6  178   180      6       2
## 105    6  181   181      6       2
## 106    6  183   180      6       2
## 107    6  180   179      6       2
## 108    6  178   178      6       2
## 109    6  178   181      6       2
## 110    6  182   181      6       2
## 111    6  181   184      6       2
## 112    6  183   183      6       2
## 113    6  183   184      6       2
## 114    6  184   186      6       2
## 115    6  187   185      6       2
## 116    6  184   185      6       2
## 117    6  185   184      6       2
## 118    6  184   187      6       2
## 119    6  186   187      6       2
## 120    6  187   185      6       2
## 121    6  186   188      6       2
## 122    6  188   189      6       2
## 123    6  189   190      6       2
## 124    6  192   194      6       2
## 125    7  194   192      7       3
## 126    7  192   191      7       3
## 127    7  190   192      7       3
## 128    7  191   191      7       3
## 129    7  189   189      7       3
## 130    7  189   188      7       3
## 131    7  190   190      7       3
## 132    7  191   191      7       3
## 133    7  190   191      7       3
## 134    7  192   194      7       3
## 135    7  193   194      7       3
## 136    7  193   195      7       3
## 137    7  195   193      7       3
## 138    7  194   192      7       3
## 139    7  193   193      7       3
## 140    7  193   194      7       3
## 141    7  194   195      7       3
## 142    7  196   193      7       3
## 143    7  195   196      7       3
## 144    7  196   196      7       3
## 145    8  196   196      8       3
## 146    8  195   193      8       3
## 147    8  192   191      8       3
## 148    8  186   182      8       3
## 149    8  182   179      8       3
## 150    8  180   180      8       3
## 151    8  181   178      8       3
## 152    8  179   178      8       3
## 153    8  177   178      8       3
## 154    8  178   179      8       3
## 155    8  179   177      8       3
## 156    8  177   177      8       3
## 157    8  177   174      8       3
## 158    8  172   174      8       3
## 159    8  175   176      8       3
## 160    8  177   177      8       3
## 161    8  179   181      8       3
## 162    8  181   176      8       3
## 163    8  177   179      8       3
## 164    8  180   180      8       3
## 165    8  180   184      8       3
## 166    8  185   188      8       3
## 167    8  188   188      8       3
## 168    9  189   189      9       3
## 169    9  188   190      9       3
## 170    9  188   183      9       3
## 171    9  175   178      9       3
## 172    9  178   178      9       3
## 173    9  180   179      9       3
## 174    9  179   176      9       3
## 175    9  177   174      9       3
## 176    9  174   176      9       3
## 177    9  176   175      9       3
## 178    9  176   178      9       3
## 179    9  178   179      9       3
## 180    9  179   175      9       3
## 181    9  175   174      9       3
## 182    9  175   175      9       3
## 183    9  174   176      9       3
## 184    9  175   172      9       3
## 185    9  173   170      9       3
## 186    9  169   171      9       3
## 187    9  172   171      9       3
## 188   10  171   174     10       4
## 189   10  172   172     10       4
## 190   10  171   174     10       4
## 191   10  174   175     10       4
## 192   10  174   177     10       4
## 193   10  177   179     10       4
## 194   10  178   178     10       4
## 195   10  178   180     10       4
## 196   10  180   181     10       4
## 197   10  181   179     10       4
## 198   10  177   179     10       4
## 199   10  177   177     10       4
## 200   10  176   176     10       4
## 201   10  176   175     10       4
## 202   10  175   173     10       4
## 203   10  171   173     10       4
## 204   10  173   173     10       4
## 205   10  172   171     10       4
## 206   10  170   167     10       4
## 207   10  167   168     10       4
## 208   10  169   170     10       4
## 209   10  169   171     10       4
## 210   11  171   174     11       4
## 211   11  176   178     11       4
## 212   11  174   177     11       4
## 213   11  176   179     11       4
## 214   11  179   182     11       4
## 215   11  182   183     11       4
## 216   11  183   182     11       4
## 217   11  184   186     11       4
## 218   11  186   185     11       4
## 219   11  188   187     11       4
## 220   11  188   188     11       4
## 221   11  190   190     11       4
## 222   11  190   190     11       4
## 223   11  190   191     11       4
## 224   11  191   191     11       4
## 225   11  191   191     11       4
## 226   11  191   190     11       4
## 227   11  190   190     11       4
## 228   11  190   190     11       4
## 229   11  191   189     11       4
## 230   11  190   190     11       4
## 231   12  190   191     12       4
## 232   12  190   189     12       4
## 233   12  190   193     12       4
## 234   12  194   192     12       4
## 235   12  194   194     12       4
## 236   12  194   196     12       4
## 237   12  193   193     12       4
## 238   12  193   195     12       4
## 239   12  195   198     12       4
## 240   12  198   198     12       4
## 241   12  198   198     12       4
## 242   12  196   196     12       4
## 243   12  196   197     12       4
## 244   12  197   195     12       4
## 245   12  196   195     12       4
## 246   12  195   194     12       4
## 247   12  194   193     12       4
## 248   12  192   193     12       4
## 249   12  194   194     12       4
## 250   12  194   193     12       4
A<-apple %>% 
   ggplot(aes(Months, Close)) +
   geom_point(aes(col=Quarter, size=2)) +
   labs(title = 'Months: {frame_time}', x = 'Months', y = 'Price (USD)') +
   transition_time(Date) +
   ease_aes('linear') +
   theme_linedraw()

A

Explanation: The animation visualizes the closing price of Apple Inc. stocks for a year divided into quarters and how the price fluctuates over a year.