#I'm trying to do a taste wheel, like the Meilgaard wheel.
I'm not trying to do anything complex I only want to plot together a pie chart and a PCA plot.
I would like to have the piechart bigger than the PCA graph.
I would like to plot the pie graph with both the two PCA graphs or with the fviz_pca_biplot.
The following is the PCA:
principal4<-PCA(ExpertWine2,scale.unit = T,ind.sup = NULL,quanti.sup =29:30,quali.sup =1,graph = T,axes = c(1,2),ncp = 3)
fviz_pca_biplot(principal4)
The following is the pie chart:
slices <- c(10, 10, 10, 10)
lbls <- c("acidity", "freshness", "sweetness", "corposity")
coloris = c("gold", "cyan", "indianred1", "burlywood4")
cake=pie(slices, labels = lbls, init.angle=45, main="Pie Chart of tastes",col=coloris)
There are multiple packages aimed at solving this. It will depend on whether you as using a base r plotting implementation or something like ggplot.
I would reccomend looking at bentobox (strict positioning), patchwork (auto positioning) and cowplot (somewhere in the middle). Patchwork is primarily aimed at ggplot but the other two should work with any plotting method.
bento box:
https://github.com/PhanstielLab/BentoBox
patchwork:
https://patchwork.data-imaginist.com/
cowplot:
https://cran.r-project.org/web/packages/cowplot/vignettes/introduction.html
Related
I want to use long/lat (EPSG:4326) coordinates in a bokeh plot and have a map in the Background.
I tried with the tile provider maps as suggested in bokeh: Mapping geo data.
But the format is in web mercator coordinates (EPSG:3857) and I don't want to convert my coordinates.
The general question how to do this is unanswered in Is it possible to set figure axis_type in bokeh to geographical (long/lat)?
My idea was to use extra axes:
from bokeh.plotting import figure, show
from bokeh.models import Range1d, LinearAxis
from bokeh.tile_providers import CARTODBPOSITRON, get_provider
tile_provider = get_provider(CARTODBPOSITRON)
p = figure(x_range=(-180, 180), y_range=(-90, 90)) # EPSG:4326
# add extra axis
p.extra_x_ranges = {"EPSG:3857x": Range1d(start=-20026376.39, end=20026376.39)}
p.extra_y_ranges = {"EPSG:3857y": Range1d(start=-20048966.10, end=20048966.10)}
# place extra axis
p.add_layout(LinearAxis(x_range_name="EPSG:3857x"), 'above')
p.add_layout(LinearAxis(y_range_name="EPSG:3857y"), 'right')
p.add_tile(tile_provider, x_range_name="EPSG:3857x", y_range_name="EPSG:3857y")
show(p)
But the map is not visible.
Is there a way to use extra axis for a tile_provider?
If you are just asking about displaying lat/lng visually on the axes, then all you have to do is set the axis type to "mercator"
p = figure(x_range=(-2000000, 6000000), y_range=(-1000000, 7000000),
x_axis_type="mercator", y_axis_type="mercator")
This is demonstrated on the documentation page you linked.
If you are asking about using data that is in lan/lng coordinates to plot on a tile plot, then you will need to convert it to Web Mercator first. The underlying coordinate system for tiles is always Web Mercator.
If you are asking about something else, then your question is not clear (please update to clarify).
I was wondering if it is possible to plot (XYPlot) a dataset in JFreeChart where the series contained in the dataset are plotted against separate y-axis ranges. The date is clustered by category/timestamp, e.g. if my dataset was this:
Timestamp Val1 Val2
2019-04-26 0.6 603
2019-04-25 2.1 1040
2019-04-24 4.1 255
It is impractical to plot both value series on the same range axis.
I've attempted extracting each series into its own dataset, so that I can call plot.mapDataSetToRangeAxis(); but when I add multiple datasets to the plot, the bars tend to render on top of each other. Perhaps I'm missing something simple?
There are a few posts that address separate elements of what I'm looking for, but think I need something that combines these two:
JFreeChart - XYBarChart Show Separate Bars for Each Series
Setting different y-axis for two series with JFreeChart
Here is the python code I'm currently using—inside inductive automation/ignition's reporting module; they allow you configure the JFreeChart prior to rendering.
def configureChart(chart):
from org.jfree.chart.axis import DateAxis
from org.jfree.data.xy import XYSeries, XYSeriesCollection
from org.jfree.chart.renderer.xy import ClusteredXYBarRenderer
from java.awt import Color
from java.text import NumberFormat
class mins_to_str(NumberFormat):
def format(self,*args,**kwargs):
r = ''
number = args[0]
hrs = number//60
mins = number%60
r = '%02i:%02i' %(hrs,mins)
if len(args)>1:
toAppendTo = args[1]
pos = args[2].getField()
r = toAppendTo.insert(pos,r)
return r
plt = chart.getPlot()
renderer = ClusteredXYBarRenderer
xax = DateAxis()
plt.setDomainAxis(xax)
for i in range(plt.getDatasetCount()):
d = plt.getDataset(i)
dsc = XYSeriesCollection()
series = XYSeries(d.getSeriesKey(0))
print('SERIES [%s]' %series)
for r in range(d.getItemCount(0)):
xv = d.getXValue(0,r)
yv = d.getYValue(0,r)
print(' X: %s (%s)' %(xv,type(xv)))
print(' Y: %s (%s)' %(yv,type(yv)))
series.add(xv,yv)
dsc.addSeries(series)
plt.setDataset(i,dsc) # assuming all of my series need to be in the same dsc for this to work...
plt.setRenderer(i,renderer)
if i > 0:
plt.mapDatasetToRangeAxis(i,1)
else:
plt.mapDatasetToRangeAxis(i,0)
plt.getRangeAxis(0).setNumberFormatOverride(mins_to_str())
Currently, I'm getting this:
Any ideas/help would be greatly appreciated.
Here is a time series chart within ignition's Report developing environment.
This one is completely setup using the Chart Options and just a tiny bit of JFreeChart scripting. Should be similar to designing a bar chart. Hope it helps.
JFreeChart Script -
#Import Java classes - Color & JFreeChart
from java.awt import Color
from org.jfree.chart.plot import CategoryPlot
#get Plot of Current Chart
plot = chart.getPlot()
#Set color of domain and range gridlines
plot.setDomainGridlinePaint(Color.black)
plot.setRangeGridlinePaint(Color.black)
How I can create interactive R plots in Power BI (for example Plotly)? Below code doesn't return any error, but also doesn't show chart:
library(plotly)
library(ggplot2)
z = ggplot(data = dataset) + geom_point(mapping = aes(x = Console, y = Search))
ggplotly(z)
Data source:
source <- "https://cdn.rawgit.com/BlueGranite/Microsoft-R-Resources/master/power-bi/gameconsole.csv"
game.console <- read.csv(source, header = TRUE)
According to this question in Power BI's Community forums
Plotly lib is supported as part of HTML support for R powered Custom
Visuals only, not R Visuals in general currently.
Plotly can only be used if it produces an IMAGE\PNG for R visuals in
PBI. Not HTML.
For Custom Visuals we have an upcoming feature which will also enable R-based custom visuals to render as htmls.
Hope this helps.
The reason is that right now Power BI only supports render charts created by R visualization component as PNG.
Try the following:
p <- plot_ly(x = dataset$period, y = dataset$mean, name = "spline", line = list(shape = "spline"))
plotly_IMAGE(p, format = "png", out_file = "out.png")
But the problem with this is that, though rendered by plotly, the visualizations will not be interactive since its just a PNG image.
If you want to create interactive visualizations using plotly. The only way you can do is to create a custom Power BI visualization and import it to your report. See this post for a good introduction.
PowerBI only supports charts rendered as PNG while plotly format is in HTML. You can try to save the chart as PNG then print it in the R console inside PowerBI.
You first have to register a plotly account here.
After registration, on the top right corner arrow next to your account name and click on Settings -> API keys. You will be able to generate API key. Copy and paste your username and API key using this code.
Sys.setenv("plotly_username"="....")
Sys.setenv("plotly_api_key"=".....")
Then add this code in to turn the plot into png format and print it out.
fig <- plot_ly(x = dataset$Console, y = dataset$Search)
Png <- plotly_IMAGE(fig, out_file = "plotly-test-image.png")
print(Png)
As mentioned in another answer, this plot won't be interactive as plot in PowerBI. To create an interactive plot in PowerBI, you have to create a custom visual. Follow an R custom visual example here or radacad example here.
For some reason I cannot get xlab and ylab to work in mosaic plots in vcd package.
I tried:
mosaic(~Sex +Survived,
data=Titanic,
shade=T,
legend=T,
main="myplot",
labeling_args=list(abbreviate = c( Sex=2, Survived=1)) ,
ylab="Gender",
xlab="survival")
this labels the axes "Sex" and "Survived" respectively.
mosaic(margin.table(Titanic, c(2,4)),
ylab="Gender",
xlab="survival",
shade=T, legend=T,
main="myplot",
labeling_args=list(abbreviate = c( Sex=2, Survived=1)))
this also labels the axes "Sex" and "Survived" respectively.
mosaicplot(margin.table(Titanic, c(2,4)),
shade=T,
legend=T,
main="myplot",
labeling_args=list(abbreviate = c(Sex=2, Survived=1)),
ylab="Gender",
xlab="survival")
this labels the axes correctly, but disregards ‘labeling_args’
Does anyone have any suggestions?
There is a huge part written on labels in the vcd documentation.
What you were looking for is this:
labeling_args = list(set_varnames = c(Sex="Gender", Survived="survival"))
It's been a while since you asked, but maybe it helps someone else ;)
The mosaic function and the mosaicplot function use very different graphic options. So it's no wonder that what works with one doesn't work with the other.
I use code like the example below to do basic plotting of a list of values from F# Interactive. When plotting more points, the time taken to display increases dramatically. In the examples below, 10^4 points display in 4 seconds whereas 4.10^4 points take a patience-testing 53 seconds to display. Overall it's roughly as if the time to plot N points is in N^2.
The result is that I'll probably add an interpolation layer in front of this code, but
1) I wonder if someone who knows the workings of FSharpChart and Windows.Forms could explain what is causing this behaviour? (The data is bounded so one thing that seems to rule out is the display needing to adjust scale.)
2)Is there a simple remedy other than interpolating the data myself?
let plotl (f:float list) =
let chart = FSharpChart.Line(f, Name = "")
|> FSharpChart.WithSeries.Style(Color = System.Drawing.Color.Red, BorderWidth = 2)
let form = new Form(Visible = true, TopMost = true, Width = 700, Height = 500)
let ctl = new ChartControl(chart, Dock = DockStyle.Fill)
form.Controls.Add(ctl)
let z1 = [for i in 1 .. 10000 do yield sin(float(i * i))]
let z2 = [for i in 1 .. 20000 do yield sin(float(i * i))]
plotl z1
plotl z2
First of all, FSharpChart is a name used in an older version of the library. The latest version is called F# Charting, comes with a new documentation and uses just Chart.
To answer your question, Chart.Line and Chart.Points are quite slow for large number of points. The library also has Chart.FastLine and Chart.FastPoints (which do not support as many features, but are faster). So, try getting the latest version of F# Charting and using the "Fast" version of the method.