Showing posts with label Data Visualization. Show all posts
Showing posts with label Data Visualization. Show all posts

Saturday, July 5, 2025

How do you visualize glucose data from a glucose CGM report using Python?

Interpretation of data from the python code from my previous post must be exercised with caution. The program explicitly puts red dots over the curve to establish verification that the method indeed achieves its objective. We have seen that the image generated does show large red circles riding the graph. 

It is easy to show by reducing the size to 0, that the curve is traced by very tiny circles shown by an underlying red ness in the trace (zoom to see). These are shown for two the two radii assumed in the next figure.

 


However, a .CSV file is generated by the code. The graphing of this file in Microsoft Excel does not show any difference between the two cases, radius=2 and radius =0 as shown.

  


The reason is these curves (one by visualization and the other set by generated CSV file) are not using the same base.

1. The cv2.circle() visualization: This is what creates the glucose_trace_detected.jpg. 

2. The matplotlib.pyplot.plot() or scatter() visualization: This is what creates the glucose_value_mg_dL plot.

However, in the plotted graphs from CSV files we find gaps in the generated graph. They can indeed correspond to event marker positions. The red dot in the visualization is only for verifying that the entire graph is captured.

We will take a look at this possibility of getting the positional data of events in the next post, as it gives us valuable information on event times. 


Wednesday, December 13, 2017

How do you plot using GGPLOT in Power BI?

We saw an example of plotting using GGPLOT earlier in the RGUI.

Herein we use ggplot in Power BI.

We connect to Northwind database on an instance of SQL Server 2016 Developer. We load data from Products and OrderDetails table into Power BI.

We drop the R Script Visual from the Visualizations onto the designer.



ggplot2
The R script editor opens up as shown


ggplot_03

Add the following code as shown:
-------------------------------
library(ggplot2)
y=ggplot(data=dataset, aes(x=ProductName, y=Quantity))
y=y + geom_point(aes(color="red"))

-------------------------
If you run this code using the R script

You get an error:


Now modify the above to this:
---------------------------
library(ggplot2)
y=ggplot(data=dataset, aes(x=ProductName, y=Quantity))
y=y+geom_point(aes(color="red"))
y=y+geom_point(aes(size=Quantity))
y

---------------------
Now run the script. You will see the plot as shown. The size shows the value of "Quantity" and the color=red is supposed to make it red.


The correct code for aes is modified to this:
-------------------
library(ggplot2)
y=ggplot(data=dataset, aes(x=ProductName, y=Quantity))
y=y+geom_point(aes(size=Quantity, color="red"))
y

-------------------
Run this code again. You get the following visualization.

Looks like there may some error in rendering of the color. Changing it to blue makes it still 'red'.



Thursday, November 5, 2015

What is needed to visualize data in R?

Basically you need a graphic program.

When you install R you already have a basic graphic package and you can verify it by using the command library() in the R Gui. If you do not have R on your computer you should get one as described here.  It is really quite easy.

Graphics_00.png

Installing R gets only Graphics in the above list of packages. While this is a basic package, you also can use the more comprehensive plotting package called ggplot2.

You install it using the following command:

> install.packages("ggplot2")

Graphics_01.png

Since it is not on the machine a list of mirror sites will be displayed where you can get the package. When I chose 'California' (US(CA 1), mirror in this list, after going to the site the program returned the message that 'ggplot2' is not available for R version 3.2.2.



When the search failed, the R Gui came up with the following command:
>chooseCranmirror()

When a different mirror site in Texas was chosen, the program was able to download and install it on the computer.
The result of installing is shown here, copied from the R GUI interface:
----
> chooseCRANmirror()
> install.packages("ggplot2")
also installing the dependencies ‘stringi’, ‘magrittr’, ‘colorspace’, ‘Rcpp’, ‘stringr’, ‘RColorBrewer’, ‘dichromat’, ‘munsell’, ‘labeling’, ‘plyr’, ‘digest’, ‘gtable’, ‘reshape2’, ‘scales’, ‘proto’

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/stringi_1.0-1.zip'
Content type 'application/zip' length 14265659 bytes (13.6 MB)
downloaded 13.6 MB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/magrittr_1.5.zip'
Content type 'application/zip' length 149844 bytes (146 KB)
downloaded 146 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/colorspace_1.2-6.zip'
Content type 'application/zip' length 393156 bytes (383 KB)
downloaded 383 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/Rcpp_0.12.1.zip'
Content type 'application/zip' length 3189762 bytes (3.0 MB)
downloaded 3.0 MB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/stringr_1.0.0.zip'
Content type 'application/zip' length 82841 bytes (80 KB)
downloaded 80 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/RColorBrewer_1.1-2.zip'
Content type 'application/zip' length 26681 bytes (26 KB)
downloaded 26 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/dichromat_2.0-0.zip'
Content type 'application/zip' length 147785 bytes (144 KB)
downloaded 144 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/munsell_0.4.2.zip'
Content type 'application/zip' length 126094 bytes (123 KB)
downloaded 123 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/labeling_0.3.zip'
Content type 'application/zip' length 40880 bytes (39 KB)
downloaded 39 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/plyr_1.8.3.zip'
Content type 'application/zip' length 1114785 bytes (1.1 MB)
downloaded 1.1 MB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/digest_0.6.8.zip'
Content type 'application/zip' length 151939 bytes (148 KB)
downloaded 148 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/gtable_0.1.2.zip'
Content type 'application/zip' length 64140 bytes (62 KB)
downloaded 62 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/reshape2_1.4.1.zip'
Content type 'application/zip' length 503481 bytes (491 KB)
downloaded 491 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/scales_0.3.0.zip'
Content type 'application/zip' length 603649 bytes (589 KB)
downloaded 589 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/proto_0.3-10.zip'
Content type 'application/zip' length 458603 bytes (447 KB)
downloaded 447 KB

trying URL 'https://cran.revolutionanalytics.com/bin/windows/contrib/3.2/ggplot2_1.0.1.zip'
Content type 'application/zip' length 2677225 bytes (2.6 MB)
downloaded 2.6 MB

package ‘stringi’ successfully unpacked and MD5 sums checked
Warning: unable to move temporary installation ‘C:\Program Files\R\R-3.2.2\library\file4b804f971e0f\stringi’ to ‘C:\Program Files\R\R-3.2.2\library\XXXXXXXXsti’
package ‘magrittr’ successfully unpacked and MD5 sums checked
package ‘colorspace’ successfully unpacked and MD5 sums checked
package ‘Rcpp’ successfully unpacked and MD5 sums checked
package ‘stringr’ successfully unpacked and MD5 sums checked
package ‘RColorBrewer’ successfully unpacked and MD5 sums checked
package ‘dichromat’ successfully unpacked and MD5 sums checked
package ‘munsell’ successfully unpacked and MD5 sums checked
package ‘labeling’ successfully unpacked and MD5 sums checked
package ‘plyr’ successfully unpacked and MD5 sums checked
package ‘digest’ successfully unpacked and MD5 sums checked
package ‘gtable’ successfully unpacked and MD5 sums checked
package ‘reshape2’ successfully unpacked and MD5 sums checked
package ‘scales’ successfully unpacked and MD5 sums checked
package ‘proto’ successfully unpacked and MD5 sums checked
package ‘ggplot2’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
        C:\Users\Jayaram\AppData\Local\Temp\XXXXXXXX\downloaded_packages
>

Now if you run the command
>library()
You will see that ggplot2 is now in the installed list as shown.

Graphics_03.png

To know more about ggplot2 go here.
Good luck with data visualization!



Tuesday, September 15, 2015

Can you install R (version 3.2.2) programming executable on Windows 10 computer?

Yes you can.

You need to download the program from here. Double clicking will let you begin installing. The installation is quite fast on Windows 10. Accept all the defaults during installation unless you need to customize. You can see all the steps in my previous installation on a Windows 7 (x64) laptop here.
After installation you will find two shortcuts as shown:

RforWindows10.png

One of them is a shortcut for the x64bit program and the other shortcut R i386 3.2.2 is a x32bit program. Probably you only need one of them. The x64 version shortcut gets added to the Start.


Sunday, September 13, 2015

What is a good way to learn R language?

There are many ways one can learn as Internet provides a whole lot of options from free sites to sites where you can
pay and register to learn.
R language has come to focus because it can be used to carry out Data Analysis as it has strong statistical basis.
Using R one can work with graphics as well. This means the analyzed data can be pictorially displayed in terms of
graphs and charts for data visualization.
Microsoft SQL Server 2016 will have built-in support for R language and it goes without saying that learning R
programming has great value.
One way, I can think of,  is to download the R programming interface on to your computer and start from there.

Downloading and Installing R language executable for Windows 7?

While it is available for Unix/Linux, it is also available for Windows (both x32bit and x64bit). You can download the latest version here (R-3.2.2-win.exe) . The version you will be downloading is R 3.2.2 for Windows (32/64) 62MB. A small file for the complicated things it does.

Here are some download/install screen shots for those who like:

If you are installing for the first time choose that option after you access the download link above.

Rforwindows01
 
The set up for R on Windows needs to be selected:


Rforwindows04

Complete the Installation wizard screens and you are done.

You can invoke it from the desktop shortcut as shown here and the R-GUI will be displayed as shown:

Rforwindows08

It can also be invoked from Command Line and it will be easier if add the directory of the R installation (C:\Program Files\R\R-3.2.2\bin;) to the Path in your environment variables set up.

After adding the above directory to the Path in environmental variables, you can launch R as shown here:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\mysorian>R
R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> q()
Save workspace image? [y/n/c]: n

Now you are ready to rock and roll. You could also use the GUI shown previously (previous image).

If you enter help.start() either from GUI as shown here.

R_helpstart.png

You can also do this from command line. Note that as shown above help.Start() would produce an error as R language happens to be case sensitive, it has to be help.start().

In both cases help appears in a browser window hosted on your local IIS as shown.


This is all for today. Visit here again for more on R programming.