2

R scatter diagram with hexadecimal colors

 2 years ago
source link: https://www.codesd.com/item/r-scatter-diagram-with-hexadecimal-colors.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

R scatter diagram with hexadecimal colors

advertisements

I've got a CSV file with 3 columns, the X values, Y values, and their corresponding hexadecimal (#RRGGBB) values. I've been trying to create a scatter/bubble plot with the insides of the bubbles colored according to the hex values.

symbols(year, logtrans, circles=size, inches=0.05, bg=intel2$HexLogClock)

intel2$HexLogClock contains the hex values.

Sorry again for the noob question, any help is appreciated.


I think your trouble may lie in the hex values not being a character. Make sure they are first. See example below:

year <- 1:5
logtrans <- log(year)
size <- rep(15,5)
intel2 <- data.frame(HexLogClock=c("#330000", "#FFFFCC", "#660000", "#FF0000", "#00FF00"),stringsAsFactors=FALSE)
symbols(year, logtrans, circles=size, inches=0.05, bg=intel2$HexLogClock)

Notice the stringsAsFactors=FALSE code, which you can specify for read.csv and other import methods to ensure your character data isn't converted to a factor.

You can do this for your data using:

intel2$HexLogClock <- as.character(intel2$HexLogClock)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK