-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Showing R plots in Juno plot pane #333
Comments
You need overloads for the correct |
thanks for the hint. I'll see how far I get. As far as Juno is concerned, probably this: https://github.com/JuliaInterop/RCall.jl/blob/master/src/ijulia.jl |
I think I got it to work. using RCall, DataFrames
@rlibrary ggplot2
df_string = DataFrame(x = randn(100), y=randn(100), z1=rand(["a"; "b"], 100), z2=rand(["darkorange"; "lightblue"], 100))
plt = ggplot(df_string) + geom_point(aes(x=:x, y=:y, color=:z2)) # works with standard colors
using ImageShow
using FileIO
rdevicefun(m::MIME"image/png") = @rget png
#rdevicefun(m::MIME"image/svg+xml", f) = R"svg($f)"
ext(::MIME"image/png") = ".png"
#ext(::MIME"image/svg+xml") = ".svg"
function Base.show(io::IO, m::MIME"image/png", plt::RObject)
f = tempname() * ext(m)
width, height = get(io, :juno_plotsize, [100, 100])
R"""
png($f, width=$width, height=$height, units="px", pointsize=20)
show($plt) # plot(rnorm(10), rnorm(10))
dev.off()
"""
show(io, m, load(f))
end
plt Before I put this into a PR I need some advice
|
Would probably make sense to use the defaults that are already in place instead of
Not really, but it might be the easiest solution for now (and is already what is used for IJulia display, so whatever).
You probably can't do any better, but for correctness you'll need to figure out a runtime check for whether you have a R-plot, and put that into
so the display system does the right thing. |
Thank you for your help! Regarding
probably some of the EDIT: I found the So the code above actually doesn't work for base plots. |
Now that I understand that
Are there such things like post-execute hooks in Juno as well? The two options I see are
|
What could be done to show rcall plots in julia-vscode? |
Is it possible to show
ggplot2
plots in the Juno plot pane?This plot is shown in a Jupyter notebook, but when run in Juno, it is shown in an R plot window.
Instead of cross-posting in the Juno repo, I am pinging @pfitzseb. If you give me hints where to start this, I would try to tackle this myself.
The text was updated successfully, but these errors were encountered: