When I try graphing my double bar graph using ggplot on r- shiny using plotly's interface, the double bar graph is getting data from random places and does not properly graph the plot.
I have used this interface on single bar plots and it has worked perfectly and correctly displays the data and graph but with double bar plots, it just uses random data? The regular ggplot plot is fine but when I transform it to a plotly it screws up.
output$tvpn <- renderPlotly({
mpolfinal4$Partner.Name= factor(mpolfinal4$Partner.Name,
levels=names(sort(table(mpolfinal4$Partner.Name),
decreasing=TRUE)))
tv = ggplot(mpolfinal4, aes(x =Partner.Name, fill=Domain.Name)) +
geom_bar(colour="black") +
theme(axis.text.x=element_text(angle=90,hjust=1)) +
ggtitle("Total Views by Partner Name, and Domain Name")
out = ggplotly(tv)
out
})
Has anyone experienced this issue/know how to fix it?
Related
I am unable to plot candlestick in Julia properly.
Here is a sample code:
using Plots
using Dates
using MarketData
using TimeSeries
gr()
ta = yahoo(:GOOG, YahooOpt(period1 = now() - Month(1)))
display(plot(ta, seriestype= :candlestick))
The output I get is below
Candlestick Plot with one colour
How to ensure that I get red & green candles?
I would update your installation. I get two colors with Julia 1.8.0-beta3 and Plots version 1.29:
https://i.stack.imgur.com/q1p7J.png
I created a plot using ggplot() and turned off linetype part of the legend using "+ guides(linetype=False)".
However, when I use the ggplotly() function it completely overrides this and still displays the linetype in the legend. My thought was I need to remove that part of the legend for the generated plotly object, but I wasn't sure how to just remove the linetype within the plotly object (p object below). I do want to keep the color legend.
An example dataset to be plotted:
library("ggplot2")
library("plotly")
dataset = read.csv("file_loc")
g = ggplot(data=dataset) +
geom_line(x=dataset$Time,
y=dataset$Values,
group=dataset$group,
linetype=dataset$group,
color=dataset$Othervalue) +
# Doesn't work when using ggplotly function
guides(linetype=FALSE)
p = ggplotly(g)
Note: I am using R version 3.6.0, ggplot2 3.3.5, plotly 4.9.4.1
I found that if I turn off the legend for p or p=layout(p,showlegend=FALSE) it turns off just the plotly legends but keeps the ggplot legends previously hidden or kept.
I have created multiple pie charts with legends in ggplot. I am also using rworldmap to create maps of Eurasia with coordinates plotted as points on the map.
The pie charts I have correspond to the points I have plotted on my maps. My end goal is to overlay the pie charts I have created in ggplot on to my rworldmap plots, and then display all of the maps in a grid. I would also like to add the legends from my ggplot pie charts to the maps.
I have added my pie chart to an object(?) AD_Pie, using AD_Pie <- ggplot(df, aes...) + etc.
I have created my map using:
AD_Map <- getMap(resolution = "low")
plot(AD_Map, xlim = c(-27.0, 174.0), ylim = c(17.5, 75.0), col = "grey",border = "darkgrey", xlab = "", ylab = '' , bg= "lightblue")
points(Coordinate_AD_Clean$long, Coordinate_AD_Clean$lat, col = "red", pch = "+")
Coordinate_AD_Clean is my data frame.
My question is whether there is a way to overlay AD_Pie on to my plot in rworldmap. There doesn't need to be any interaction between the two plots, so hypothetically it would be enough to have even an image of the pie chart overlayed on to the map saved as a single plot that I can then add to a grid/matrix of all the completed plots.
There is a mapPies function in rworldmap and some functionality to add new pie charts to maps using this package, but the pies I have created in ggplot have taken significant data formatting and tweaking to get to, so using this function is not really an option.
I am very much hoping that some sort of overlaying function exists in either ggplot or rworldmap that I can use to put these pieces together. If you can help I would appreciate it greatly. Thanks for reading, and let me know if any further information is required.
Not exactly an answer, but solutions may be easier by using the ggmap package instead of rworldmap.
I developed a Shiny app with ggplot, and for technical reasons I have to keep on using it. I am trying to create a tooltip system, as the one you can see over here with Dygraphs : http://dygraphs.com/gallery/#g/plotter
There is a solution suggested on SOF, but I don't like it as it's not as user-friendly as the previous one : ToolTip when you mouseover a ggplot on shiny.
Here, there's an area under the plot in which the value is printed, and you have to click over to get the value.
library(ggplot2)
a <- ggplot(data = economics, aes(x = date, y = unemploy))
a <- a + geom_line()
a
My question is : how to develop the same tooltip as Dygraph with ggplot ?
Thanks a bunch ;)
Attempting to create pie chart with ggplot2 but cannot seem to get it using other references online. The chart I create is missing most of its fill.
ggplot(sae,aes(x=1,fill=factor(State), width=1))+
geom_bar()+
ggtitle("House by State")+
coord_polar(theta='y')
This code gives:
How do I fill the center?
Any other improvements appreciated.
With sample data
sae <- data.frame(State=sample(LETTERS[1:6],60,T))
ggplot(sae,aes(x=factor(1),fill=factor(State)))+
geom_bar(width=1)+
ggtitle("House by State")+
coord_polar(theta="y")
EDIT: Other options (because piecharts are bad)
#following Jaaps example: some better way to visualize this
#grouped barchart
p1 <- ggplot(sae, aes(x=State, fill=State)) +
geom_bar() + labs(title="grouped barchart")
#stacked barchart; especially practical if you want to compare groups
sae$group <- rbinom(60,1,0.5)
p2 <- ggplot(sae, aes(x=factor(group),fill=State))+
geom_bar(width=0.5) + labs(title="grouped stacked barchart")
do.call(grid.arrange,list(grobs=list(p1,p2),ncol=2))
As #Heroka already mentioned in the comments, pie-charts are a bad way of visualizing information. They are bad that it is even mentioned in the help-files of R.
From ?pie:
Pie charts are a very bad way of displaying information. The eye is
good at judging linear measures and bad at judging relative areas. A
bar chart or dot chart is a preferable way of displaying this type of
data.
Cleveland (1985), page 264: “Data that can be shown by pie charts
always can be shown by a dot chart. This means that judgements of
position along a common scale can be made instead of the less accurate
angle judgements.” This statement is based on the empirical
investigations of Cleveland and McGill as well as investigations by
perceptual psychologists.
Some further reading on the pie-chart debate.
With the example data of #Heroka:
ggplot(sae,aes(x = factor(1), fill = factor(State)))+
geom_bar(width = 1, position = "dodge")+
ggtitle("House by State")
you get:
A clear demonstration that it's better to see the differences between the categories when you use a barchart instead of a piechart.
When you want to show information about proportions, there is another choice, the waffle package which gets back more to what you probably intend to show with a pie chart (i.e., proportions). In most instances, the bar plots above would likely be best, but for the sake of showing another way of plotting...
Using the sae data from above:
library(waffle) # install the package if you don't have it
w <- table(sae)
w.waf <- waffle(table(sae))
w.waf + ggtitle("Contextless Waffle Graph") + theme(plot.title=element_text(face="bold", size=24))
which yields this: