{"id":4256,"date":"2024-08-17T20:43:31","date_gmt":"2024-08-18T04:43:31","guid":{"rendered":"https:\/\/crm270s.abramjmeister.com\/?p=4256"},"modified":"2024-08-17T20:43:31","modified_gmt":"2024-08-18T04:43:31","slug":"stripe-month-by-month-revenue-graph-generating-r-code","status":"publish","type":"post","link":"https:\/\/crm270s.mycpamytax.com\/?p=4256","title":{"rendered":"Stripe month by month revenue graph generating R code"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code># Install and load the necessary packages.  Below three lines can be dropped after installation once.\ninstall.packages(\"RSQLite\")\ninstall.packages(\"DBI\")\ninstall.packages(\"ggplot2\")\nlibrary(RSQLite)\nlibrary(DBI)\nlibrary(ggplot2)\n\n# Define the path to your SQLite database\ndb_path &lt;- \"\/home\/jbyungrokim\/CSV\/CSV.db\"\n\n# Connect to the SQLite database\nconn &lt;- dbConnect(RSQLite::SQLite(), dbname = db_path)\n\n# Query to calculate the monthly total of the 'gross' field, grouped by year and month\nquery &lt;- \"\nSELECT \n    strftime('%Y-%m', created) AS YearMonth, \n    SUM(gross) AS Total_Gross\nFROM \n    'Itemized_balance_change_from_activity_USD_2022-03-11_to_2024-08-05_America-Anchorage'\nWHERE \n    strftime('%Y-%m', created) IS NOT NULL\nGROUP BY \n    YearMonth\nORDER BY \n    YearMonth;\n\"\n\n# Execute the query and store the result in a data frame\nmonthly_totals &lt;- dbGetQuery(conn, query)\n\n# Close the connection to the SQLite database\ndbDisconnect(conn)\n\n# Convert YearMonth to a Date type for better plotting\nmonthly_totals$YearMonth &lt;- as.Date(paste0(monthly_totals$YearMonth, \"-01\"), format = \"%Y-%m-%d\")\n\n# Create a line plot using ggplot2\nggplot(monthly_totals, aes(x = YearMonth, y = Total_Gross)) +\n  geom_line(color = \"blue\", linewidth = 1) +  # Updated to use 'linewidth' instead of 'size'\n  geom_point(color = \"red\", size = 2) +\n  labs(title = \"Monthly Total Gross Over Time\",\n       x = \"Month-Year\",\n       y = \"Total Gross\") +\n  theme_minimal() +\n  theme(axis.text.x = element_text(angle = 45, hjust = 1))\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[26],"tags":[],"class_list":["post-4256","post","type-post","status-publish","format-standard","hentry","category-codes"],"_links":{"self":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts\/4256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4256"}],"version-history":[{"count":0,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts\/4256\/revisions"}],"wp:attachment":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}