I am trying to create a simple dotplot that contains 100+ points, some of which are grouped close together. I need the points to be individually labeled, but I would like to stack the labels for points that are close together on top of each other.
Basically, I would like to create a similar dotplot with labeling to the graph below.
As a code example, consider the following code where I would like to add the car name to the dotplot in a way similar to the graphic.
ggplot(mtcars, aes(x = mpg)) +
geom_dotplot(binwidth = .4, stackdir = "centerwhole") +
scale_y_continuous(NULL, breaks = NULL)
I want to draw a combined bar plot, so that I can make comparision among different score types.
compare_data = data.frame(model=c(lr,rf,gbm,xgboost),
precision=c(0.6593,0.7588,0.6510,0.7344),
recall=c(0.5808,0.6306,0.4897,0.6416),f1=c(0.6176,0.6888,0.5589,0.6848),
acuracy=c(0.6766,0.7393,0.6453,0.7328))
compare1 <- ggplot(evaluation_4model, aes(x=Model, y=Precision)) +
geom_bar(aes(fill = Model), stat="identity")
compare1 <- compare+labs(title = "Precision")
Here is one of the barplot I draw, and this is the type of "precision", however, I want to make a wide bar plot, with all the models under 4 score types sharing the same Y-axis, also with subtitle if possible.
Your code throws an error, because evaluation_4model is not defined.
However, the answer to your problem is likely to make a faceted plot and hence melt the data to a long format. To do this, I usually make use of the reshape library. Tweaking your code looks like this
library(ggplot2)
library(reshape2)
compare_data = data.frame(model=c("lr","rf","gbm","xgboost"),
precision=c(0.6593,0.7588,0.6510,0.7344),
recall=c(0.5808,0.6306,0.4897,0.6416),
f1=c(0.6176,0.6888,0.5589,0.6848),
acuracy=c(0.6766,0.7393,0.6453,0.7328))
plotdata <- melt(compare_data,id.vars = "model")
compare2 <- ggplot(plotdata, aes(x=model, y=value)) +
geom_bar(aes(fill = model), stat="identity")+
facet_grid(~variable)
compare2
does that help?
I'm trying to get a graph like this to show boxplot distributions for each age group:
But instead my plot looks like this:
How can I get the boxplots to show rather than the points? Why is my Y axis non numeric?
My data looks like this:
And here's the plot code I am trying:
p2 <- ggplot(data = popSample, aes(x = AGEGRP, y = TOT_POP)) +
geom_boxplot(aes(group = AGEGRP)) +
scale_x_discrete() +
theme_light()
p2
Thank you for helping someone who is learning,
I have a Date column and Value column. I did my research on internet and tried every possible thing but it does not shows my the trend line graph. I am totally confused what is happening in my data. I have shared my code below:
ggplot(data = New, aes(x = OrderDate, y = TotalAmountWithGST))+
geom_line(color = "#00AFBB", size = 2) + scale_x_date(date_labels = "%b/%Y")
ggplot(x, aes(x = OrderDate, y = TotalAmountWithGST)) +
geom_line()+
theme_minimal()
I am trying to plot a line graph that shows a monthly trend but somehow I am getting a graph that is similar to bar graph but its not a line graph.
You need to add a geom_smooth to your ggplot code.
It's hard to replicate a working example without sample data but that should get you on the right path.
I would like a plot that looks like this:
Using ggplot. The one above was made from heatscatter in the LSD package.
I tried using this code:
p = ggplot(data = emr.ext.melt, aes(Date,NDVI))
p + geom_point() + stat_density2d(aes(fill=..level..), geom="polygon") +
scale_fill_gradient(low="blue", high="green")+ scale_y_continuous(limits = c(-1, 1))
But, got this weird plot. I just want a scatter plot colored based on the density of points for that given day. I do not want to use hexplot either.
Thank you for your help!